问题
I'm stuck trying to mask data for a scatter plot. All data seems to plot.
I'm using numpy arrays as shown in the snippet below. I'm thinking that perhaps I cannot mask on the "c" array. I can't seem to find any documentation for doing this. I'll try with the "s" array.
Any help is greatly appreciated.
yy = NP.ma.array(yy)
xx = NP.ma.array(xx)
zz_masked = NP.ma.masked_where(zz <= 1.0e6 , zz)
scatter(xx,yy,s=15,c=zz_masked, edgecolors='none')
cbar = colorbar()
show()
回答1:
Works for me. Each call to scatter() gets its own colorbar since each scatter()'s colors are normalized to its own data. Which version of matplotlib are you using?
import pylab as plt
import numpy as np
x = np.linspace(0, 1, 100)
y = x**2
z = y
z_masked = np.ma.masked_where(z > 0.5, z)
plt.scatter(x, y, c=z, s=15, edgecolors='none')
plt.colorbar()
plt.scatter(x+1, y, c=z_masked, s=15, edgecolors='none')
plt.colorbar()
plt.show()
来源:https://stackoverflow.com/questions/6392719/python-scatter-plot-with-numpy-masked-arrays