Reputation: 486
When plotting a 3d surface using the mlab.surf()
function, the presence of Nan
values results in odd plotting behavior. Any ideas of what I may be doing wrong would be appreciated.
In[37]: import mayavi
In[38]: print mayavi.__version__
4.4.0
from mayavi import mlab
j = np.copy('some 2d-array') # where j is shape (680, 680) and contains Nans
mlab.surf(j)
If I replace NaNs with the minimum value, the plot looks fine, but has an artificial plane around the edges that I want clipped:
j[np.isnan(j)]=j[~np.isnan(j)].min()
mlab.surf(j) # where j has been set to j.min() where j==np.nan
If I then add a mask that corresponds to areas where j==j.min()
, I get the weird output again (I've also tried this by creating a mask directly on the array prior to redefining the NaNs):
m = np.ma.masked_where(j==j.min(), j).mask
mlab.surf(j, mask=m)
Upvotes: 2
Views: 1086
Reputation: 22449
I would try something like this:
#first mask all the NaN:
maskedarray = np.ma.masked_invalid(j)
from mayavi import mlab
mlab.figure(1, fgcolor=(0, 0, 0), bgcolor=(1, 1, 1))
surH = mlab.surf(maskedarray, warp_scale='auto', mask=maskedarray.mask)
mlab.show()
Upvotes: 2