quiver questions/issues (bug?)

Hi all,

I've been messing with quiver a bit, and have some confusions:

according to the docs:

"""
units: [‘width’ | ‘height’ | ‘dots’ | ‘inches’ | ‘x’ | ‘y’ ]

         arrow units; the arrow dimensions except for length are in multiples of this unit.
"""

and yes, when I change units from 'dots' for 'inched', the length of the arrows do indeed change.

"""
angles: [‘uv’ | ‘xy’ | array]
     ... Alternatively, arbitrary angles may be specified as an array of values in degrees, CCW from the x-axis.
"""

This crashes for me with:

Traceback (most recent call last):
   File "quiver_test.py", line 72, in <module>
     plt.draw()
   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/pyplot.py", line 341, in draw
     get_current_fig_manager().canvas.draw()
   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 215, in draw
     FigureCanvasAgg.draw(self)
   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/backend_agg.py", line 279, in draw
     self.figure.draw(self.renderer)
   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/figure.py", line 772, in draw
     for a in self.axes: a.draw(renderer)
   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py", line 1601, in draw
     a.draw(renderer)
   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/quiver.py", line 425, in draw
     verts = self._make_verts(self.U, self.V)
   File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/quiver.py", line 484, in _make_verts
     theta = ma.asarray(self.angles*np.pi/180.0).filled(0)
TypeError: can't multiply sequence by non-int of type 'float'

I've enclosed a small test script...

Thanks,

-Chris

quiver_test.py (1.21 KB)

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

Christopher Barker wrote:

Hi all,

I've been messing with quiver a bit, and have some confusions:

one more issue with quiver -- autoscaling fails if there is a NaN in the data:

x = (1,2)
y = (1,2)
u = (2,2)
v = (-2,2)

fig = plt.figure(1)
fig.clear()

ax = fig.add_subplot(2,2,3)

# fails for a nan data point if auto-scaling
u = (2, np.nan)
props = {'units' : "dots",
          'scale' : .1,
          'width' : 2,
          'headwidth': 2,
          'headlength': 3,
          'headaxislength': 4,
          }

ax.quiver( x, y, u, v, **props )

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

Christopher Barker wrote:

Hi all,

I've been messing with quiver a bit, and have some confusions:

No, you hit a bug. Thanks for the report and test script. It is fixed in r7103.

If you are not running from svn, a workaround may be to specify the angles as an ndarray or masked array with the shape set to (N,1) where N is the number of arrows. I haven't tested it, but based on the changes I made, I think this will work with the version you have.

Eric

···

according to the docs:

"""
units: [‘width’ | ‘height’ | ‘dots’ | ‘inches’ | ‘x’ | ‘y’ ]

        arrow units; the arrow dimensions except for length are in multiples of this unit.
"""

and yes, when I change units from 'dots' for 'inched', the length of the arrows do indeed change.

"""
angles: [‘uv’ | ‘xy’ | array]
    ... Alternatively, arbitrary angles may be specified as an array of values in degrees, CCW from the x-axis.
"""

This crashes for me with:

Traceback (most recent call last):
  File "quiver_test.py", line 72, in <module>
    plt.draw()
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/pyplot.py", line 341, in draw
    get_current_fig_manager().canvas.draw()
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/backend_tkagg.py", line 215, in draw
    FigureCanvasAgg.draw(self)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/backends/backend_agg.py", line 279, in draw
    self.figure.draw(self.renderer)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/figure.py", line 772, in draw
    for a in self.axes: a.draw(renderer)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes.py", line 1601, in draw
    a.draw(renderer)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/quiver.py", line 425, in draw
    verts = self._make_verts(self.U, self.V)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/quiver.py", line 484, in _make_verts
    theta = ma.asarray(self.angles*np.pi/180.0).filled(0)
TypeError: can't multiply sequence by non-int of type 'float'

I've enclosed a small test script...

Thanks,

-Chris

------------------------------------------------------------------------

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects

------------------------------------------------------------------------

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Christopher Barker wrote:

Christopher Barker wrote:

Hi all,

I've been messing with quiver a bit, and have some confusions:

one more issue with quiver -- autoscaling fails if there is a NaN in the data:

I just committed a change to ensure that nans and infs are treated as masked points.

If you still see the problem (and I suspect you will), then it is inherent in the autoscaling.

Eric

···

x = (1,2)
y = (1,2)
u = (2,2)
v = (-2,2)

fig = plt.figure(1)
fig.clear()

ax = fig.add_subplot(2,2,3)

# fails for a nan data point if auto-scaling
u = (2, np.nan)
props = {'units' : "dots",
          'scale' : .1,
          'width' : 2,
          'headwidth': 2,
          'headlength': 3,
          'headaxislength': 4,
          }

ax.quiver( x, y, u, v, **props )

-Chris

Eric Firing wrote:

No, you hit a bug. Thanks for the report and test script. It is fixed in r7103.

If you are not running from svn, a workaround may be to specify the angles as an ndarray or masked array with the shape set to (N,1) where N is the number of arrows.

Yes, that seems to work. Thanks!

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

Christopher Barker wrote:

If you are not running from svn, a workaround may be to specify the angles as an ndarray or masked array with the shape set to (N,1) where N is the number of arrows.

Yes, that seems to work. Thanks!

However, I'm a bit confused now -- if I specify the angles explicitly, how do I specify the lengths of the arrows? The docs aren't clear on this point:

  *angles*: ['uv' | 'xy' | array]
         With the default 'uv', the arrow aspect ratio is 1, so that
         if *U*==*V* the angle of the arrow on the plot is 45 degrees
         CCW from the *x*-axis.
         With 'xy', the arrow points from (x,y) to (x+u, y+v).
         Alternatively, arbitrary angles may be specified as an array
         of values in degrees, CCW from the *x*-axis.

does it use sqrt(x^2+y^2) as the length?

Also:

    *units*: ['width' | 'height' | 'dots' | 'inches' | 'x' | 'y' ]
         arrow units; the arrow dimensions *except for length* are in
         multiples of this unit.

         * 'x' or 'y': *X* or *Y* data units

         The arrows scale differently depending on the units. For
         'x' or 'y', the arrows get larger as one zooms in;

which makes it sound like when you set "units" to 'x' or 'y' that the length does get set to those units...

What I'd like to be able to do is set the angles with "angles" and set the length in y units, but i can't figure out how to do that.

Thanks,
-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

Christopher Barker wrote:

Christopher Barker wrote:

If you are not running from svn, a workaround may be to specify the angles as an ndarray or masked array with the shape set to (N,1) where N is the number of arrows.

Yes, that seems to work. Thanks!

However, I'm a bit confused now -- if I specify the angles explicitly, how do I specify the lengths of the arrows? The docs aren't clear on this point:

  *angles*: ['uv' | 'xy' | array]
         With the default 'uv', the arrow aspect ratio is 1, so that
         if *U*==*V* the angle of the arrow on the plot is 45 degrees
         CCW from the *x*-axis.
         With 'xy', the arrow points from (x,y) to (x+u, y+v).
         Alternatively, arbitrary angles may be specified as an array
         of values in degrees, CCW from the *x*-axis.

does it use sqrt(x^2+y^2) as the length?

no, it is always sqrt(u^2+v^2), which then gets scaled according to the "units" setting together with the "scale" setting.

Also:

    *units*: ['width' | 'height' | 'dots' | 'inches' | 'x' | 'y' ]
         arrow units; the arrow dimensions *except for length* are in
         multiples of this unit.

         * 'x' or 'y': *X* or *Y* data units

         The arrows scale differently depending on the units. For
         'x' or 'y', the arrows get larger as one zooms in;

which makes it sound like when you set "units" to 'x' or 'y' that the length does get set to those units...

Correct.

What I'd like to be able to do is set the angles with "angles" and set the length in y units, but i can't figure out how to do that.

quiver(times, np.zeros((len(times),)), lengths, np.zeros(len(lengths)), angles=angles, units='y', scale=scale)

Something like that should do it. I am assuming you are plotting time series. Of course, lengths and times must be the same length (where I am assuming they are 1-D). I'm also assuming your data are coming as lengths and angles, not as components.

Eric

···

Thanks,
-Chris