I think you are using the masked array and/or the np.where incorrectly.

ratio = np.where(A >= B, A/B, B/A)

ratio = np.ma.masked_array(ratio, mask=(~np.isfinite(ratio)))

And then do a contourf on ratio.

Ben Root

## ···

On Tue, Feb 1, 2011 at 1:48 PM, Jeremy Conlin <jlconlin@…287…> wrote:

On Tue, Feb 1, 2011 at 11:22 AM, Benjamin Root <ben.root@…1304…> wrote:

On Tue, Feb 1, 2011 at 11:58 AM, Jeremy Conlin <jlconlin@…287…> wrote:

I have two arrays and I want to plot the ratio of A/B when A>=B or B/A

when A<B. I can create numpy masked arrays to find the result in

these two instances, but I’m having trouble plotting them. Below I

have a minimal example. I get a plot, but only from the second time I

issue the pcolormesh command. Is there a way to combine the two

arrays for plotting or to plot without overlapping?

Thanks,

Jeremy

Try this:

ratio = numpy.where(A >= B, A/B, B/A)

Figure = pyplot.figure()

pyplot.pcolormesh(ratio)

I hope that helps!

numpy.where helps a lot. To further complicate things, some elements

of A or B are zero which causes A/B or B/A to be infinite in some

places. I can use numpy.where or create a masked array to elimnate

those elements that are infinite, but then my plotted values are

either 0 or 1 (False or True); I lose all the interesting data. The

documents of pcolormesh show that I can pass a masked_array, but I’m

successful in doing that. Do you have another trick you can show to

help me get around this problem?

Thanks again,

Jeremy