Python scatter plot with masked masked arrays

I'm stuck trying to mask data for a scatter plot. All data is apparently displayed.

I am using numpy arrays as shown in the snippet below. I think that maybe I cannot mask the array "c". I can't seem to find documentation for this. I will try with an array of "s".

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()
+3
source share
1 answer

It works for me. Each scatter () function call gets its own color bar, since each scatter () color is normalized to its own data. What 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()
+1
source

All Articles