You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would be nice if plot_surface() could plot masked arrays. Unlike imshow() which really plots the masked data, plot_surface() only plots the non-masked data.
Here is an example:
import numpy as np
import pylab as mpl
from mpl_toolkits.mplot3d import axes3d
x = np.arange(1,10,1)
y = np.arange(1,10,1)
x,y = np.meshgrid(x,y)
z = x**3 + y**3 - 500
z = np.ma.masked_array(z, z<0)
cm = mpl.cm.jet
ax1 = mpl.subplot(1,2,1, projection='3d')
ax1.plot_surface(x,y,z,
rstride=1, cstride=1, linewidth=0,
cmap=cm)
ax2 = mpl.subplot(1,2,2)
ax2.imshow(z, cmap=cm)
mpl.show()
And how should the colourmap behave in this case? Normalised to the
min/max of the unmasked values?
I'm plotting measurement data and want to mask all values which
are probabely measurement errors. Thus, normalising the colourmap
to the unmasked values would be correct for my use case.
That would be incorrect in the general case. Often, masked values may be nans or unitialized garbage. As a general rule in mpl, you don't unmask input data.
Of course, we probably should clarify terminology here...
"unmasked" as a verb means to take a masked array and remove its mask
"unmasked" as a noun means the elements of the masked array where the mask is False.
So, rereading @AndreasMatthias statement, I think you meant the noun. (whereas I was using the verb)
@WeatherGod, I was just about to clarify what I meant but I see you got there before me. I meant the noun. I should normalise the colourmap using only the values whose mask evaluates to False. This is exactly what @AndreasMatthias expects as default behaviour.
This will require a little more work, since all I did in that picture was to simply not add the polygons to the Poly3DCollection if their mask was True.
Would there be wider interest for me to continue my efforts for this cause?
Oh, absolutely. I would certainly welcome any sort of assistance here. Do note that I am about to embark on a refactoring of the plot_surface code with regards to documentation, shading, facecolors and such. We probably should coordinate so that we don't start stepping on each others' toes here.
Activity
dmcdougall commentedon Feb 29, 2012
I hacked together a very basic solution.
Would something like this be suitable?
AndreasMatthias commentedon Feb 29, 2012
Yes, that's what I was looking for. Great.
dmcdougall commentedon Feb 29, 2012
And how should the colourmap behave in this case? Normalised to the min/max of the unmasked values?
AndreasMatthias commentedon Feb 29, 2012
Damon McDougall wrote:
I'm plotting measurement data and want to mask all values which
are probabely measurement errors. Thus, normalising the colourmap
to the unmasked values would be correct for my use case.
WeatherGod commentedon Feb 29, 2012
That would be incorrect in the general case. Often, masked values may be nans or unitialized garbage. As a general rule in mpl, you don't unmask input data.
WeatherGod commentedon Feb 29, 2012
Of course, we probably should clarify terminology here...
"unmasked" as a verb means to take a masked array and remove its mask
"unmasked" as a noun means the elements of the masked array where the mask is False.
So, rereading @AndreasMatthias statement, I think you meant the noun. (whereas I was using the verb)
dmcdougall commentedon Feb 29, 2012
@WeatherGod, I was just about to clarify what I meant but I see you got there before me. I meant the noun. I should normalise the colourmap using only the values whose mask evaluates to False. This is exactly what @AndreasMatthias expects as default behaviour.
This will require a little more work, since all I did in that picture was to simply not add the polygons to the Poly3DCollection if their mask was True.
Would there be wider interest for me to continue my efforts for this cause?
WeatherGod commentedon Feb 29, 2012
Oh, absolutely. I would certainly welcome any sort of assistance here. Do note that I am about to embark on a refactoring of the plot_surface code with regards to documentation, shading, facecolors and such. We probably should coordinate so that we don't start stepping on each others' toes here.
temmeand commentedon Jul 3, 2015
Any progress on this?
techdragon commentedon Jul 22, 2019
Has anyone else got solutions they can suggest?