On 2/9/12 10:49 AM, Jeff Whitaker wrote:
> On 2/9/12 9:05 AM, Andreas H. wrote:
>> Hi,
>>
>> I'm trying to use pcolor on a masked array. I would like masked elements
>> to show up in a special color. I have written some code, but it does not
>> seem to work:
>>
>> I would appreciate any help :)
>>
>> Cheers,
>> Andreas.
>>
>> ---8<-------
>>
>> import matplotlib as mpl
>> import matplotlib.pyplot as plt
>>
>> from numpy import linspace
>> from numpy.random import randn
>> from numpy.ma import masked_invalid
>>
>> D = randn(12*72).reshape((12,72))
>> D[4,:] = nan
>> D[6,6] = nan
>>
>> D = masked_invalid(D)
>>
>> cmap = mpl.cm.bwr
>> cmap.set_bad('k', 1.)
>>
>> xbin = linspace(0, 12, 13)
>> ybin = linspace(-90, 90, 73)
>>
>> fig = plt.figure()
>> spl = fig.add_subplot(111)
>> pl = spl.pcolor(xbin, ybin, D.T, cmap=cmap, edgecolors='none',
>>                   vmin=-5, vmax=5)
> Andreas:  That's because pcolor only fills polygons that are not masked
> - it does do anything with the masked ones.
>
>   From the docstring:
>
> *X*, *Y* and *C* may be masked arrays.  If either C[i, j], or one
>           of the vertices surrounding C[i,j] (*X* or *Y* at [i, j], [i+1, j],
>           [i, j+1],[i+1, j+1]) is masked, *]nothing is plotted.
>
> I suppose pcolor could be modified to fill the masked polygons with the
> color indicated by cmap.set_bad - I think that's what most people would
> expect.
>
> -Jeff
>
>
BTW: pcolormesh will do what you want.

-Jeff

-- 
Jeffrey S. Whitaker         Phone  : (303)497-6313
Meteorologist               FAX    : (303)497-6449
NOAA/OAR/PSD  R/PSD1        Email  : jeffrey.s.whita...@noaa.gov
325 Broadway                Office : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web    : http://tinyurl.com/5telg


------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to