On Tue, Feb 1, 2011 at 1:48 PM, Jeremy Conlin <jlcon...@gmail.com> wrote:
> On Tue, Feb 1, 2011 at 11:22 AM, Benjamin Root <ben.r...@ou.edu> wrote:
> >
> >
> > On Tue, Feb 1, 2011 at 11:58 AM, Jeremy Conlin <jlcon...@gmail.com>
> 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
>
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
------------------------------------------------------------------------------
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@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users