tags:

views:

25

answers:

1
+1  Q: 

pylab 2d plotting

Hello,

im using the pcolor plot in pylab to plot a two dimensional arrays with values between 0 and 1.

Some array entries do not make sense and i want some other color for them in the plot meaning they are not valid.

I tried to call pcolor two times with a differente color map hoping pylab would overlap them, but that didnt work.

How could I do this?

Thanks a lot, Thomas

A: 

You can use masked arrays with pcolor. This is, by default, coloured white when plotted. Setting the background colour to something else will change this.

i.e.


# Set the background colour for the axes (green in this example)
matplotlib.rcParams['axes.facecolor'] = 'green'
# Make an identity array
data = np.eye(3)
# Convert to a masked array
masked_data = np.ma.array(data)
# Initialise the mask
masked_data.mask = False
# Now mask the middle data point
masked_data.mask[1,1] = True
# Plot
pcolor(masked_data)
Brendan
Thanks a lot Brendan, that solves my problem. Only thing, i cant find where to change the default color for masked values?
Thomas
You change the background color of the axes using the `rcParams` as in the example and all following plots will be green, to set the colour for the current plot only use `gca().set_axis_bgcolor('green')`
Brendan
Thank you very much for your help!
Thomas