Gap when using contourf and nan's

Dear all,

I’m trying to to show where one set of values have NaN’s on the contour plot of another set of values. I do this by creating a mask as such:

fld = randn(4,4)

fld[:2,:2] = np.nan

mask[mask==0] = np.nan

contourf(arange(4),arange(4),fld)

contourf(arange(4),arange(4),mask)

The problem is that the mask patch doesn’t cover the empty space in the fld contour. Is there any way to make this happen?

My ultimate goal is something like this:

fld2 = randn(4,4)

contourf(arange(4),arange(4),fld2)

contourf(arange(4),arange(4),mask,[1,1], extend=‘both’,

     colors='w', alpha=0.5)

to present where fld has NaN’s on the fld2 plot.

Many thanks in advance!

Bror Jonsson

“If you have a garden and a Library, You have everything you need.” -Cicero

···

==============================================================

Associate Research Scholar

Princeton University

Department of Geosciences
113 Guyot Hall
Princeton, NJ 08544-1003

USA

AIM, Skype, gTalk: brorfred

Phone: +1-617-818-1096

Hello Bror,

It is not clear from your code snippets exactly what you are asking for. Please can you post a full runnable example?

Ian Thomas

···

On 14 November 2012 21:05, Bror Jonsson <brorlist@…287…> wrote:

Dear all,

I’m trying to to show where one set of values have NaN’s on the contour plot of another set of values. I do this by creating a mask as such:

fld = randn(4,4)

fld[:2,:2] = np.nan

mask[mask==0] = np.nan

contourf(arange(4),arange(4),fld)

contourf(arange(4),arange(4),mask)

The problem is that the mask patch doesn’t cover the empty space in the fld contour. Is there any way to make this happen?

My ultimate goal is something like this:

fld2 = randn(4,4)

contourf(arange(4),arange(4),fld2)

contourf(arange(4),arange(4),mask,[1,1], extend=‘both’,

     colors='w', alpha=0.5)

to present where fld has NaN’s on the fld2 plot.

Many thanks in advance!

Bror Jonsson