I want to make a surface plot from a two dimensional array, where the z-values are stored (similar to an image where the pixel values are given).
My data is an 512x512 array like:
Z
Out[85]:
array([[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
...,
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.],
[0., 0., 0., ..., 0., 0., 0.]])
The values of interest are in the center part of the picture.
Image where only the central circular region is to be plotted as a surface plot
I did the surface plot with:
X = np.arange(1, 513)
Y = np.arange(1, 513)
X, Y = np.meshgrid(X, Y)
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(X, Y, Z, vmin=0.01)
plt.show()
The result is:
Resulting Image without any masking or thresholding
Apart from a bad style I only want to plot the circular central region and not plotting the outer square region where all values are zero.
How can I give a threshold or a mask to the values? Or is there a much better approach? I would really appreciate an example since I am pretty new to python/numpy ect.
Thank you very much!
One way to suppress plotting of zeros in your surface plot, is by replacing the zeros (or all values you do not want to plot) in your Z-Array with nans like this:
Z[Z==0]=np.nan
This should give you your the desired plot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With