python - Matplotlib plot_surface mplot3d with masked array and custom palette gives wrong color -
i'm trying plot surface in 3d using mplot3d matplotlib. want custom color palette values above 1.0 green, below -1.0 blue, 0.0 red(invalid values) , other values according greyscale. i've been able of these right except condition 0.0 should red. following this example thought may able set 0.0 "bad value" in masked array fails.
this snippet try plot values:
import numpy np import matplotlib.pyplot plt import matplotlib.colors colors matplotlib import cm mpl_toolkits.mplot3d import axes3d ... fig = plt.figure() ax = fig.add_subplot(111, projection='3d') masked_array = np.ma.masked_equal(z,0.0) palette = cm.gray palette.set_over('g', 1.0) palette.set_under('b', 1.0) palette.set_bad('r', 1.0) ax.plot_surface(x,y,masked_array, rstride=1, cstride=1, cmap=palette, norm = colors.normalize(vmin = -1.0, vmax = 1.0, clip = false)) plt.savefig('plot.png')
now run z set 2d numpy array many 0.0 values:
>>> print z == 0.0 [[false true true true true true true true true false] [false true true true true true true true true false] [false true true true true true true true true false] [false true true true true true true true true false] [false true true true true true true true true false] [false false false false false false false false false false] [false false false false false false false false false false] [false false false false false false false false false false] [false false false false false false false false false false] [false false false false false false false false false false]]
and expect surface many red squares. instead this:
can explain or me achieve same effect in other way? clarify, want z-values equal 0.0 marked invalid coloring them red while rest of graph should follow greyscale palette.
Comments
Post a Comment