Skip to content

Plotting masked arrays with plot_surface() #487

Closed

Description

@AndreasMatthias

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()

Activity

  1. dmcdougall commented on Feb 29, 2012

    @dmcdougall
    Member

    I hacked together a very basic solution.

    Would something like this be suitable?

  2. AndreasMatthias commented on Feb 29, 2012

    @AndreasMatthias
    Author

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

  3. dmcdougall commented on Feb 29, 2012

    @dmcdougall
    Member

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

  4. AndreasMatthias commented on Feb 29, 2012

    @AndreasMatthias
    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.

  5. WeatherGod commented on Feb 29, 2012

    @WeatherGod
    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.

  6. WeatherGod commented on Feb 29, 2012

    @WeatherGod
    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)

  7. dmcdougall commented on Feb 29, 2012

    @dmcdougall
    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?

  8. WeatherGod commented on Feb 29, 2012

    @WeatherGod
    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.

  9. added this to the milestone on Aug 18, 2014
  10. temmeand commented on Jul 3, 2015

    @temmeand

    Any progress on this?

  11. techdragon commented on Jul 22, 2019

    @techdragon

    Has anyone else got solutions they can suggest?

  12. modified the milestones: , v3.5.0 on Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions