3

When I plot an array with masked values, using matplotlib countourf, the masked values appear white. I want them to appear grey.

I tried the set_bad method, but it seems countourf doesn't recognize it (although it recognizes the set_over and set_under methods).

Is there any other method I can use with contourf?

Or will I have to change my code to use imshow, which understands set_bad, instead of countourf?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
carla
  • 2,181
  • 19
  • 26
  • 2
    For what it's worth, `contourf` and `contour` differ from `imshow` in that they simply don't draw anything where the array is masked. They're not making the masked areas white, it's just the background of the plot showing through. This is why they don't have a `set_bad` method. – Joe Kington Jun 11 '13 at 11:42

1 Answers1

6

Have you tried setting first the background, like:

x,y=meshgrid(linspace(0,1),linspace(0,1))
fig=plt.figure()
a=fig.add_subplot(111,axisbg='gray')
z=ma.masked_array(x**2-y**2,mask=y>-x+1)
a.contourf(z)
gg349
  • 21,996
  • 5
  • 54
  • 64
  • 1
    Knowing now that contourf simply doesn't draw anything where the array is masked, this will certainly work! – carla Jun 11 '13 at 12:51