Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Rightclick on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: <jasonsage@cr...>  20090213 18:08:27

A student of mine recently noticed that sometimes, quiver plots were coming up empty (using the plot_vector_field function from Sage, which passes everything on to quiver). Upon investigation, we saw that some of the array entries passed in were infinity because of where we happened to evaluate the function. It was relatively easy to correct in our case (change the evaluation to miss the bad point), but is there a better way to handle this? Can this be considered a bug in quiver (i.e., returning a blank plot when one of the vectors has an infinite coordinate?). Here is some example code illustrating the problem: import pylab import numpy step=1 X,Y = numpy.meshgrid( numpy.arange(1,1.1,step),numpy.arange(1,1.1,step) ) U = 1/X V = Y pylab.figure() Q = pylab.quiver( X,Y,U, V) pylab.savefig("test.png") When you change step to something that avoids an evaluation at x=0 (say, step=0.13), you get a nice plot. Is this something that we should be preprocessing in Sage before calling quiver, masking those "bad" points or something? I haven't used masking before, but I'd like to fix Sage's plot_vector_field function to return something sensible, even when the function happens to be infinite at one of the points. Thanks, Jason  Jason Grout 
From: Ryan May <rmay31@gm...>  20090213 18:42:01
Attachments:
Message as HTML

On Fri, Feb 13, 2009 at 12:08 PM, <jasonsage@...> wrote: > > A student of mine recently noticed that sometimes, quiver plots were > coming up empty (using the plot_vector_field function from Sage, which > passes everything on to quiver). Upon investigation, we saw that some > of the array entries passed in were infinity because of where we > happened to evaluate the function. It was relatively easy to correct in > our case (change the evaluation to miss the bad point), but is there a > better way to handle this? Can this be considered a bug in quiver (i.e., > returning a blank plot when one of the vectors has an infinite > coordinate?). > > Here is some example code illustrating the problem: > > > import pylab > import numpy > step=1 > X,Y = numpy.meshgrid( numpy.arange(1,1.1,step),numpy.arange(1,1.1,step) ) > U = 1/X > V = Y > pylab.figure() > Q = pylab.quiver( X,Y,U, V) > pylab.savefig("test.png") > > When you change step to something that avoids an evaluation at x=0 (say, > step=0.13), you get a nice plot. > > Is this something that we should be preprocessing in Sage before calling > quiver, masking those "bad" points or something? I haven't used masking > before, but I'd like to fix Sage's plot_vector_field function to return > something sensible, even when the function happens to be infinite at one > of the points. > I'm not sure why quiver does not plot any arrows in that case, but it's also easy enough to mask out the values yourself: U = 1/X U = numpy.ma.array(U, mask=numpy.isinf(U)) V = Y V = numpy.ma.array(V, mask=numpy.isinf(V)) You can also catch NaN values by using ~numpy.isfinite() instead of numpy.isinf(). Ryan  Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma 
From: Eric Firing <efiring@ha...>  20090213 19:17:43

Ryan May wrote: > On Fri, Feb 13, 2009 at 12:08 PM, <jasonsage@... > <mailto:jasonsage@...>> wrote: > > > A student of mine recently noticed that sometimes, quiver plots were > coming up empty (using the plot_vector_field function from Sage, which > passes everything on to quiver). Upon investigation, we saw that some > of the array entries passed in were infinity because of where we > happened to evaluate the function. It was relatively easy to correct in > our case (change the evaluation to miss the bad point), but is there a > better way to handle this? Can this be considered a bug in quiver (i.e., > returning a blank plot when one of the vectors has an infinite > coordinate?). > > Here is some example code illustrating the problem: > > > import pylab > import numpy > step=1 > X,Y = numpy.meshgrid( > numpy.arange(1,1.1,step),numpy.arange(1,1.1,step) ) > U = 1/X > V = Y > pylab.figure() > Q = pylab.quiver( X,Y,U, V) > pylab.savefig("test.png") > > When you change step to something that avoids an evaluation at x=0 (say, > step=0.13), you get a nice plot. > > Is this something that we should be preprocessing in Sage before calling > quiver, masking those "bad" points or something? I haven't used masking > before, but I'd like to fix Sage's plot_vector_field function to return > something sensible, even when the function happens to be infinite at one > of the points. > > > I'm not sure why quiver does not plot any arrows in that case, but it's > also easy enough to mask out the values yourself: > > U = 1/X > U = numpy.ma.array(U, mask=numpy.isinf(U)) > V = Y > V = numpy.ma.array(V, mask=numpy.isinf(V)) > > You can also catch NaN values by using ~numpy.isfinite() instead of > numpy.isinf(). This is a good use case for numpy.ma.masked_invalid: In [2]:numpy.ma.masked_invalid? Type: function Base Class: <type 'function'> String Form: <function masked_invalid at 0xb62bccdc> Namespace: Interactive File: /usr/local/lib/python2.5/sitepackages/numpy/ma/core.py Definition: numpy.ma.masked_invalid(a, copy=True) Docstring: Mask the array for invalid values (NaNs or infs). Any preexisting mask is conserved. Eric > > Ryan > >  > Ryan May > Graduate Research Assistant > School of Meteorology > University of Oklahoma > > >  > >  > Open Source Business Conference (OSBC), March 2425, 2009, San Francisco, CA > OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise > Strategies to boost innovation and cut costs with open source participation > Receive a $600 discount off the registration fee with the source code: SFAD > http://p.sf.net/sfu/XcvMzF8H > > >  > > _______________________________________________ > Matplotlibusers mailing list > Matplotlibusers@... > https://lists.sourceforge.net/lists/listinfo/matplotlibusers 
From: <jasonsage@cr...>  20090213 20:30:46

Eric Firing wrote: > Ryan May wrote: >> On Fri, Feb 13, 2009 at 12:08 PM, <jasonsage@... >> <mailto:jasonsage@...>> wrote: >> >> >> A student of mine recently noticed that sometimes, quiver plots were >> coming up empty (using the plot_vector_field function from Sage, >> which >> passes everything on to quiver). Upon investigation, we saw that >> some >> of the array entries passed in were infinity because of where we >> happened to evaluate the function. It was relatively easy to >> correct in >> our case (change the evaluation to miss the bad point), but is >> there a >> better way to handle this? Can this be considered a bug in quiver >> (i.e., >> returning a blank plot when one of the vectors has an infinite >> coordinate?). >> >> Here is some example code illustrating the problem: >> >> >> import pylab >> import numpy >> step=1 >> X,Y = numpy.meshgrid( >> numpy.arange(1,1.1,step),numpy.arange(1,1.1,step) ) >> U = 1/X >> V = Y >> pylab.figure() >> Q = pylab.quiver( X,Y,U, V) >> pylab.savefig("test.png") >> >> When you change step to something that avoids an evaluation at >> x=0 (say, >> step=0.13), you get a nice plot. >> >> Is this something that we should be preprocessing in Sage before >> calling >> quiver, masking those "bad" points or something? I haven't used >> masking >> before, but I'd like to fix Sage's plot_vector_field function to >> return >> something sensible, even when the function happens to be infinite >> at one >> of the points. >> >> >> I'm not sure why quiver does not plot any arrows in that case, but >> it's also easy enough to mask out the values yourself: >> >> U = 1/X >> U = numpy.ma.array(U, mask=numpy.isinf(U)) >> V = Y >> V = numpy.ma.array(V, mask=numpy.isinf(V)) >> >> You can also catch NaN values by using ~numpy.isfinite() instead of >> numpy.isinf(). > > This is a good use case for numpy.ma.masked_invalid: > > In [2]:numpy.ma.masked_invalid? > Type: function > Base Class: <type 'function'> > String Form: <function masked_invalid at 0xb62bccdc> > Namespace: Interactive > File: /usr/local/lib/python2.5/sitepackages/numpy/ma/core.py > Definition: numpy.ma.masked_invalid(a, copy=True) > Docstring: > Mask the array for invalid values (NaNs or infs). > Any preexisting mask is conserved. > Thanks for both of your replies. So I tried the following: import pylab import numpy step=1 X,Y = numpy.meshgrid( numpy.arange(1,1.1,step),numpy.arange(1,1.1,step) ) U = numpy.ma.masked_invalid(1/X) V = numpy.ma.masked_invalid(Y) pylab.figure() Q = pylab.quiver( X,Y,U, V) pylab.savefig("test.png") and I still didn't get a plot. I noticed two things: 1. The unmasked portion of each array might be different; I hope quiver can handle that. 2. Even when I called pylab.quiver(X,Y,U,U) (so that the masks lined up), I still didn't get a plot. Does quiver handle masks properly, or did I just do something wrong? Jason 
From: Ryan May <rmay31@gm...>  20090213 20:32:06
Attachments:
Message as HTML

On Fri, Feb 13, 2009 at 2:30 PM, <jasonsage@...> wrote: > Eric Firing wrote: > >> Ryan May wrote: >> >>> On Fri, Feb 13, 2009 at 12:08 PM, <jasonsage@... <mailto: >>> jasonsage@...>> wrote: >>> >>> >>> A student of mine recently noticed that sometimes, quiver plots were >>> coming up empty (using the plot_vector_field function from Sage, which >>> passes everything on to quiver). Upon investigation, we saw that some >>> of the array entries passed in were infinity because of where we >>> happened to evaluate the function. It was relatively easy to correct >>> in >>> our case (change the evaluation to miss the bad point), but is there a >>> better way to handle this? Can this be considered a bug in quiver >>> (i.e., >>> returning a blank plot when one of the vectors has an infinite >>> coordinate?). >>> >>> Here is some example code illustrating the problem: >>> >>> >>> import pylab >>> import numpy >>> step=1 >>> X,Y = numpy.meshgrid( >>> numpy.arange(1,1.1,step),numpy.arange(1,1.1,step) ) >>> U = 1/X >>> V = Y >>> pylab.figure() >>> Q = pylab.quiver( X,Y,U, V) >>> pylab.savefig("test.png") >>> >>> When you change step to something that avoids an evaluation at x=0 >>> (say, >>> step=0.13), you get a nice plot. >>> >>> Is this something that we should be preprocessing in Sage before >>> calling >>> quiver, masking those "bad" points or something? I haven't used >>> masking >>> before, but I'd like to fix Sage's plot_vector_field function to >>> return >>> something sensible, even when the function happens to be infinite at >>> one >>> of the points. >>> >>> >>> I'm not sure why quiver does not plot any arrows in that case, but it's >>> also easy enough to mask out the values yourself: >>> >>> U = 1/X >>> U = numpy.ma.array(U, mask=numpy.isinf(U)) >>> V = Y >>> V = numpy.ma.array(V, mask=numpy.isinf(V)) >>> >>> You can also catch NaN values by using ~numpy.isfinite() instead of >>> numpy.isinf(). >>> >> >> This is a good use case for numpy.ma.masked_invalid: >> >> In [2]:numpy.ma.masked_invalid? >> Type: function >> Base Class: <type 'function'> >> String Form: <function masked_invalid at 0xb62bccdc> >> Namespace: Interactive >> File: /usr/local/lib/python2.5/sitepackages/numpy/ma/core.py >> Definition: numpy.ma.masked_invalid(a, copy=True) >> Docstring: >> Mask the array for invalid values (NaNs or infs). >> Any preexisting mask is conserved. >> >> > Thanks for both of your replies. So I tried the following: > > import pylab > import numpy > step=1 > X,Y = numpy.meshgrid( numpy.arange(1,1.1,step),numpy.arange(1,1.1,step) ) > U = numpy.ma.masked_invalid(1/X) > V = numpy.ma.masked_invalid(Y) > pylab.figure() > Q = pylab.quiver( X,Y,U, V) > pylab.savefig("test.png") > > and I still didn't get a plot. I noticed two things: > > 1. The unmasked portion of each array might be different; I hope quiver can > handle that. > > 2. Even when I called pylab.quiver(X,Y,U,U) (so that the masks lined up), I > still didn't get a plot. > > Does quiver handle masks properly, or did I just do something wrong? > It should, but there was a release with a bug in the masked support for quiver. What version are you running? import matplotlib; print matplotlib.__version__ Ryan  Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma Sent from: Norman Oklahoma United States. 
From: <jasonsage@cr...>  20090213 20:38:24

Ryan May wrote: >> > Try changing your plot limits. :) > > pylab.xlim(3,3) > pylab.ylim(3,3) > Aha! Perfect; thank you! I'll fix this in Sage now... Jason 
Sign up for the SourceForge newsletter:
No, thanks