color missing value with contourf

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

···

On Tue, Feb 1, 2011 at 11:09 AM, Francesco Benincasa <francesco.benincasa@…3419…> 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