Hi,
I've got (what seems to me) a nice clean, self-contained implementation
of wind barbs plots. I'd like to see if I can get this into matplotlib,
as it would be very useful to the meteorology community. I've borrowed
heavily from Quiver for rounding out rough edges (like multiple calling
signatures) as for templates for documentation. The base
implementation, though, seems much simpler (thanks to Mike's transforms)
and is based more on scatter.
Right now it monkey-patches Axes so that it can be a stand-alone file.
Just running the file should give a good example of the expected output.
My only concern up front is if a new axes method is appropriate, since
this is somewhat domain specific. But I'd like to at least get the new
Collections class included, since otherwise, I have no idea how to get
this distributed to the community at large.
I welcome any comments/criticism to help improve this.
Ryan
--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma
'''
Support for plotting a field of (wind) barbs. This is like quiver in that
you have something that points along a vector field giving direction, but
the magnitude of the vector is given schematically by the presence of barbs
or flags on the barb. This differs from quiver, which uses the size of the
arrow to indicate vector magnitude.
'''
import numpy as np
from numpy import ma
from matplotlib import rcParams
import matplotlib.collections as mcoll
import matplotlib.transforms as mtransforms
import matplotlib.artist as martist
_barbs_doc = """
Plot a 2-D field of barbs.
call signatures::
barb(U, V, **kw)
barb(U, V, C, **kw)
barb(X, Y, U, V, **kw)
barb(X, Y, U, V, C, **kw)
Arguments:
*X*, *Y*:
The x and y coordinates of the barb locations
(default is head of barb; see *pivot* kwarg)
*U*, *V*:
give the *x* and *y* components of the barb shaft
*C*:
an optional array used to map colors to the barbs
All arguments may be 1-D or 2-D arrays or sequences. If *X* and *Y*
are absent, they will be generated as a uniform grid. If *U* and *V*
are 2-D arrays but *X* and *Y* are 1-D, and if len(*X*) and len(*Y*)
match the column and row dimensions of *U*, then *X* and *Y* will be
expanded with :func:`numpy.meshgrid`.
*U*, *V*, *C* may be masked arrays, but masked *X*, *Y* are not
supported at present.
Keyword arguments:
*scale*:
Length of the barb in points; the other parts of the barb
are scaled against this.
Default is 9
*pivot*: [ 'tip' | 'middle' ]
The part of the arrow that is at the grid point; the arrow
rotates about this point, hence the name *pivot*.
*barbcolor*: [ color | color sequence ]
Specifies the color all parts of the barb except any flags.
This parameter is analagous to the *edgecolor* parameter
for polygons, which can be used instead. However this parameter
will override facecolor.
*flagcolor*: [ color | color sequence ]
Specifies the color of any flags on the barb.
This parameter is analagous to the *facecolor* parameter
for polygons, which can be used instead. However this parameter
will override facecolor. If this is not set (and *C* has not either)
then *flagcolor* will be set to match *barbcolor* so that the barb
has a uniform color. If *C* has been set, *flagcolor* has no effect.
*pivot*: [ 'tip' | 'middle' ]
The part of the arrow that is at the grid point; the arrow
rotates about this point, hence the name *pivot*.
Barbs are traditionally used in meteorology as a way to plot the speed
and direction of wind observations, but can technically be used to plot
any two dimensional vector quantity. As opposed to arrows, which give
vector magnitude by the length of the arrow, the barbs give more quantitative
information about the vector magnitude by putting slanted lines or a triangle
for various increments in magnitude, as show schematically below:
/\\
/ \\
/\\\
/ \\\
--
The largest increment is given by a triangle (or "flag"), which usually
represents inrements of 50. After those come full lines, which represent 10.
The smallest increment is a half line, which represents 5. There is only, of
course, ever at most 1 half line. If the magnitude is small and only needs a
single half-line and no full lines or triangles, the half-line is offset from
the end of the barb so that it can be easily distinguished from barbs with a
single full line. The magnitude for the barb shown above would nominally be
65.
linewidths and edgecolors can be used to customize the barb.
Additional :class:`~matplotlib.collections.PolyCollection`
keyword arguments:
%(PolyCollection)s
""" % martist.kwdocd
class Barbs(mcoll.PolyCollection):
'''
Specialized PolyCollection for barbs.
There are no API methods. Everything is performed in __init__().
There is one internal function _find_tails() which finds exactly