Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plotting masked arrays with plot_surface() #487

Closed
AndreasMatthias opened this issue Sep 22, 2011 · 10 comments · Fixed by #20725
Closed

Plotting masked arrays with plot_surface() #487

AndreasMatthias opened this issue Sep 22, 2011 · 10 comments · Fixed by #20725

Comments

@AndreasMatthias
Copy link

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()
@ghost ghost assigned WeatherGod Sep 22, 2011
@dmcdougall
Copy link
Member

I hacked together a very basic solution.

Would something like this be suitable?

@AndreasMatthias
Copy link
Author

Yes, that's what I was looking for. Great.

@dmcdougall
Copy link
Member

And how should the colourmap behave in this case? Normalised to the min/max of the unmasked values?

@AndreasMatthias
Copy link
Author

Damon McDougall wrote:

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.

@WeatherGod
Copy link
Member

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
Copy link
Member

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
Copy link
Member

@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
Copy link
Member

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.

@tacaswell tacaswell added this to the unassigned milestone Aug 18, 2014
@temmeand
Copy link

temmeand commented Jul 3, 2015

Any progress on this?

@techdragon
Copy link

Has anyone else got solutions they can suggest?

tomneep added a commit to tomneep/matplotlib that referenced this issue Jul 29, 2020
@tomneep tomneep mentioned this issue Jul 29, 2020
6 tasks
@QuLogic QuLogic modified the milestones: unassigned, v3.5.0 Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants