[matplotlib-devel] (Wind) Barbs

2008-07-15 Thread Ryan May

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
  

Re: [matplotlib-devel] simple question about important classes

2008-07-15 Thread Gael Varoquaux
Bonjour,

C'est dangeureux dans m'envoyer un email dans ma boite mail particulière.
C'est la meilleur moyen de ne jamais recevoir de réponse: je reçoit 200
email par jour, et je les lis en diagonale. Enfin, j'image que c'était
une erreur, et que l'e-mail aurait dû partir à la mailing list
matplotlib-dev.

On Tue, Jul 15, 2008 at 06:42:01PM +0200, David Kaplan wrote:
> I have a hopefully simple question that perhaps you could help me with.
> I am trying to add the possibility of manual selection of contour label
> locations to clabel (as in matlab), and I want to use the class
> BlockingMouseInput in contour.py, but I can't figure out how to import
> that class correctly into contour.py.  Could you give me a hint?

Hum, I am not too sure what you are trying to do. It has been a while
since I have used Matlab, so I don't think I know what feature you are
refering too. Could you please elaborate both by describing what you are
trying to achieve in terms of end-user experience, and by giving a simple
example of the code you are trying to get to run.

Cheers,

Gaël

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel


Re: [matplotlib-devel] (Wind) Barbs

2008-07-15 Thread John Hunter
On Tue, Jul 15, 2008 at 5:37 PM, Ryan May <[EMAIL PROTECTED]> wrote:

> I welcome any comments/criticism to help improve this.

Hey Ryan,

I have looked at this code briefly and have a few minor comments.  I
think Eric, who did the bulk of the current quiver implementation, and
as an oceanographer is in a field much closer to yours than mine, will
provide more useful feedback and should ultimately handle the patch
submission.

My first comment is that the code looks very good -- it is well
thought out and commented, and t is definitely suitable for inclusion
in the main line.  Certainly the Barbs class can live in the
collections module.  You note in the driver code that you are worried
about pollution of the axes namespace by including a domain specific
method, and this is a reasonable worry, but the axes namespace is
currently so polluted with plotting methods that it is a small worry.
I think it would be fine for you to rework your code into a patch
which provides the Barbs collection in matplotlib.collections, an Axes
method, and a pyplot interface function (with a pylab module level
docstring entry).  The overloading of the Axes namespace is not ideal,
but it's what we've got.

My second comment has to do with your comment at the end of the example:

 #Showing colormapping with uniform grid. Unfortunately, only the flags
 #on barbs get colormapped this way.

On a cursory read of the code, it looks like you have implemented
everything as a single poly collection, and the reason the flags only
get colored is that the varicolored is black.  It seems like there are
two solutions: write your class as a combination of poly collection
(for the flags) and line collection (for the barbs) and colormap both
(there are some line collection colormapping examples in the examples
subdir courtesy of Eric).  The 2nd alternative, which I haven't
explored, is to set the edgecolor equal to the facecolor and support
colormapping of the edgecolors.

Overall this is very promising, and I wish you the best trying to make
mpl serviceble to the meteorology community.  Jeff Whitaker has done a
phenomenal job with basemap providing extensions for those needing
cartographic projections as a toolkit.  Depending on how far you want
to go with meteorological support, we can include the changes in the
mainline or fold them into a toolkit if they become hyper-specialized.

JDH

-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
___
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel