plotting masked arrays with plot_surface()

I would like to plot a masked array with plot_surface().
But unlike imshow() which really plots the masked data,
plot_surface() only plots the non-masked data.

How can I plot the masked array?

Ciao
Andreas

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

Andreas,

I once had a patch I made for someone else with this request, but it broke a bunch of things for regular uses of plot_surface, so I never added it. I will see if I can dig it up for you as a work-around.

In the meantime, could you file a feature request for this in the github tracker, please?

Ben Root

···

On Thu, Sep 22, 2011 at 2:31 PM, Andreas Matthias <andreas.matthias@…287…> wrote:

I would like to plot a masked array with plot_surface().

But unlike imshow() which really plots the masked data,

plot_surface() only plots the non-masked data.

How can I plot the masked array?

Ciao

Andreas

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 = x3 + y3 - 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()