Benjamin Root <ben.root@...> writes:
>
> On Tue, Feb 1, 2011 at 11:09 AM, Francesco Benincasa <francesco.benincasa-
[email protected]> wrote:
>
> Hi all,
> I'm using pygrads for plotting maps from netcdf files.
> I use the contourf method, but I'm not able to fill the region where there are
> no value (there is the missing value -999) with a color. It seems to ignore
> the set_bad method that I used to make the colormap.
> Any suggestions?
> Thank you very much in advance.
> --
> | Francesco Benincasa
>
>
> Most likely, the issue is that set_bad is more for setting the color when
encountering masked values (through masked arrays). As a quick and dirty way
to
deal with it, try setting that color through the set_under() method.The correct
way to do this is to use set_bad, but convert your numpy array that you are
displaying into a masked array like so:z_ma = np.ma.masked_array(z, mask=(z ==
-999))and use contourf on z_ma.Let us know how that works for you.Ben Root
>
>
>
> ------------------------------------------------------------------------------
> Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
> Finally, a world-class log management solution at an even better price-free!
> Download using promo code Free_Logger_4_Dev2Dev. Offer expires
> February 28th, so secure your free ArcSight Logger TODAY!
> http://p.sf.net/sfu/arcsight-sfd2d
>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
Hi !
I have had the same issue (set_bad not taking effect with nans), and
transformed
the data into a masked array. But it does not seem to work...
Here a minimal example:
import matplotlib.pyplot as plt
import numpy as np
plt.clf()
x = np.linspace(-180,180,100)
y = np.linspace(-90,90,100)
x, y = np.meshgrid(x,y)
data = np.cos(x/180*np.pi) + np.sin(y/180*np.pi)
data[(y<50)&(y>30)&(x<50)&(x>30)] = np.nan
data = np.ma.masked_array(data, mask = np.isnan(data)) # has no effect
ncol = 20
cbar = [-1,1]
palette = plt.cm.Blues
palette.set_bad('green')
palette.set_over('red')
palette.set_under('black')
cs = plt.contourf(x,y,data,np.linspace(cbar[0],cbar[1],ncol), cmap=palette,
extend='both')
plt.colorbar()
cs.set_clim(cbar) # need that for set_upper and set_lower to take effect
plt.show()
There is already that small bug where one needs to call set_clim for set_upper
and set_lower, maybe something similar is needed for set_bad?
Any idea?
Many thanks,
Mahe
------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the
endpoint security space. For insight on selecting the right partner to
tackle endpoint security challenges, access the full report.
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users