
 m[c           @` s  d  Z  d d l m Z m Z m Z m Z d d l Z d d l Z d d l Z d d l	 Z
 d d l	 m Z d d l j Z d d l j Z d d l j Z d d l j Z d d l m Z d d l m Z d d l j Z d d l m Z d d l m Z d	 e j  j! Z" d
 Z# d e j$ f d     YZ% d   Z& d   Z' d e j( f d     YZ) d e j  j! Z* e j  j+ d e*  d e j( f d     YZ, d S(   u  
Support for plotting vector fields.

Presently this contains Quiver and Barb. Quiver plots an arrow in the
direction of the vector, with the size of the arrow related to the
magnitude of the vector.

Barbs are like quiver in that they point along a vector, but
the magnitude of the vector is given schematically by the presence of barbs
or flags on the barb.

This will also become a home for things such as standard
deviation ellipses, which can and will be derived very easily from
the Quiver code.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   ma(   t   allow_rasterization(   t	   docstring(   t   delete_masked_points(   t   CirclePolygonu  
Plot a 2-D field of arrows.

Call signatures::

  quiver(U, V, **kw)
  quiver(U, V, C, **kw)
  quiver(X, Y, U, V, **kw)
  quiver(X, Y, U, V, C, **kw)

*U* and *V* are the arrow data, *X* and *Y* set the location of the
arrows, and *C* sets the color of the arrows. These 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 and *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`.

The default settings auto-scales the length of the arrows to a reasonable size.
To change this behavior see the *scale* and *scale_units* kwargs.

The defaults give a slightly swept-back arrow; to make the head a
triangle, make *headaxislength* the same as *headlength*. To make the
arrow more pointed, reduce *headwidth* or increase *headlength* and
*headaxislength*. To make the head smaller relative to the shaft,
scale down all the head parameters. You will probably do best to leave
minshaft alone.

*linewidths* and *edgecolors* can be used to customize the arrow
outlines.

Parameters
----------
X : 1D or 2D array, sequence, optional
    The x coordinates of the arrow locations
Y : 1D or 2D array, sequence, optional
    The y coordinates of the arrow locations
U : 1D or 2D array or masked array, sequence
    The x components of the arrow vectors
V : 1D or 2D array or masked array, sequence
    The y components of the arrow vectors
C : 1D or 2D array, sequence, optional
    The arrow colors
units : [ 'width' | 'height' | 'dots' | 'inches' | 'x' | 'y' | 'xy' ]
    The arrow dimensions (except for *length*) are measured in multiples of
    this unit.

    'width' or 'height': the width or height of the axis

    'dots' or 'inches': pixels or inches, based on the figure dpi

    'x', 'y', or 'xy': respectively *X*, *Y*, or :math:`\sqrt{X^2 + Y^2}`
    in data units

    The arrows scale differently depending on the units.  For
    'x' or 'y', the arrows get larger as one zooms in; for other
    units, the arrow size is independent of the zoom state.  For
    'width or 'height', the arrow size increases with the width and
    height of the axes, respectively, when the window is resized;
    for 'dots' or 'inches', resizing does not change the arrows.
angles : [ 'uv' | 'xy' ], array, optional
    Method for determining the angle of the arrows. Default is 'uv'.

    'uv': the arrow axis aspect ratio is 1 so that
    if *U*==*V* the orientation of the arrow on the plot is 45 degrees
    counter-clockwise from the horizontal axis (positive to the right).

    'xy': arrows point from (x,y) to (x+u, y+v).
    Use this for plotting a gradient field, for example.

    Alternatively, arbitrary angles may be specified as an array
    of values in degrees, counter-clockwise from the horizontal axis.

    Note: inverting a data axis will correspondingly invert the
    arrows only with ``angles='xy'``.
scale : None, float, optional
    Number of data units per arrow length unit, e.g., m/s per plot width; a
    smaller scale parameter makes the arrow longer. Default is *None*.

    If *None*, a simple autoscaling algorithm is used, based on the average
    vector length and the number of vectors. The arrow length unit is given by
    the *scale_units* parameter
scale_units : [ 'width' | 'height' | 'dots' | 'inches' | 'x' | 'y' | 'xy' ], None, optional
    If the *scale* kwarg is *None*, the arrow length unit. Default is *None*.

    e.g. *scale_units* is 'inches', *scale* is 2.0, and
    ``(u,v) = (1,0)``, then the vector will be 0.5 inches long.

    If *scale_units* is 'width'/'height', then the vector will be half the
    width/height of the axes.

    If *scale_units* is 'x' then the vector will be 0.5 x-axis
    units. To plot vectors in the x-y plane, with u and v having
    the same units as x and y, use
    ``angles='xy', scale_units='xy', scale=1``.
width : scalar, optional
    Shaft width in arrow units; default depends on choice of units,
    above, and number of vectors; a typical starting value is about
    0.005 times the width of the plot.
headwidth : scalar, optional
    Head width as multiple of shaft width, default is 3
headlength : scalar, optional
    Head length as multiple of shaft width, default is 5
headaxislength : scalar, optional
    Head length at shaft intersection, default is 4.5
minshaft : scalar, optional
    Length below which arrow scales, in units of head length. Do not
    set this to less than 1, or small arrows will look terrible!
    Default is 1
minlength : scalar, optional
    Minimum length as a multiple of shaft width; if an arrow length
    is less than this, plot a dot (hexagon) of this diameter instead.
    Default is 1.
pivot : [ 'tail' | 'mid' | 'middle' | 'tip' ], optional
    The part of the arrow that is at the grid point; the arrow rotates
    about this point, hence the name *pivot*.
color : [ color | color sequence ], optional
    This is a synonym for the
    :class:`~matplotlib.collections.PolyCollection` facecolor kwarg.
    If *C* has been set, *color* has no effect.

Notes
-----
Additional :class:`~matplotlib.collections.PolyCollection`
keyword arguments:

%(PolyCollection)s

See Also
--------
quiverkey : Add a key to a quiver plot
ue  
Add a key to a quiver plot.

Call signature::

  quiverkey(Q, X, Y, U, label, **kw)

Arguments:

  *Q*:
    The Quiver instance returned by a call to quiver.

  *X*, *Y*:
    The location of the key; additional explanation follows.

  *U*:
    The length of the key

  *label*:
    A string with the length and units of the key

Keyword arguments:

  *angle* = 0
    The angle of the key arrow. Measured in degrees anti-clockwise from the
    x-axis.

  *coordinates* = [ 'axes' | 'figure' | 'data' | 'inches' ]
    Coordinate system and units for *X*, *Y*: 'axes' and 'figure' are
    normalized coordinate systems with 0,0 in the lower left and 1,1
    in the upper right; 'data' are the axes data coordinates (used for
    the locations of the vectors in the quiver plot itself); 'inches'
    is position in the figure in inches, with 0,0 at the lower left
    corner.

  *color*:
    overrides face and edge colors from *Q*.

  *labelpos* = [ 'N' | 'S' | 'E' | 'W' ]
    Position the label above, below, to the right, to the left of the
    arrow, respectively.

  *labelsep*:
    Distance in inches between the arrow and the label.  Default is
    0.1

  *labelcolor*:
    defaults to default :class:`~matplotlib.text.Text` color.

  *fontproperties*:
    A dictionary with keyword arguments accepted by the
    :class:`~matplotlib.font_manager.FontProperties` initializer:
    *family*, *style*, *variant*, *size*, *weight*

Any additional keyword arguments are used to override vector
properties taken from *Q*.

The positioning of the key depends on *X*, *Y*, *coordinates*, and
*labelpos*.  If *labelpos* is 'N' or 'S', *X*, *Y* give the position
of the middle of the key arrow.  If *labelpos* is 'E', *X*, *Y*
positions the head, and if *labelpos* is 'W', *X*, *Y* positions the
tail; in either of these two cases, *X*, *Y* is somewhere in the
middle of the arrow+label key object.
t	   QuiverKeyc           B` s   e  Z d  Z i d d 6d d 6d d 6d d 6Z i d d 6d	 d 6d d 6d d 6Z i d
 d 6d
 d 6d d 6d d 6Z d   Z d   Z e e _ d   Z	 d   Z
 d   Z e d    Z d   Z d   Z d   Z e Z RS(   u3    Labelled arrow for use as a quiver plot scale key.u   centeru   Nu   Su   leftu   Eu   rightu   Wu   bottomu   topu   middleu   tipu   tailc   	   
   ` s  t  j j |   | |  _ | |  _ | |  _ | |  _ | j d d  |  _ | j d d  |  _	 | j d d   |  _ | |  _ | j d d  |  _ |  j | j j j |  _ t j |       f d   } | j j j j d	 |  |  _ | j d
 d  |  _ | j d d   |  _ | j d t    |  _ | |  _ |  j } t j d | d |  j |  j d |  j |  j d t  j! |    |  _" |  j d  k	 r|  j" j# |  j  n  t$ |  _% | j& d |  _& d  S(   Nu   anglei    u   coordinatesu   axesu   coloru   labelsepg?c         ` s8       } | d  k	 r4 | j |  j | _ t | _ n  d  S(   N(   t   Nonet   _labelsep_inchest   dpit   labelsept   Falset   _initialized(   t   figt   self_weakref(   t	   weak_self(    s0   lib/python2.7/site-packages/matplotlib/quiver.pyt   on_dpi_change  s    	u   dpi_changedu   labelposu   Nu
   labelcoloru   fontpropertiest   textt   horizontalalignmentt   verticalalignmentt   fontproperties('   t   martistt   Artistt   __init__t   Qt   Xt   Yt   Ut   popt   anglet   coordR
   t   colort   labelR   t   axt   figureR   R   t   weakreft   reft	   callbackst   connectt   _cidt   labelpost
   labelcolort   dictR   t   kwt   mtextt   Textt   halignt   valignt   font_managert   FontPropertiesR   t	   set_colorR   R   t   zorder(	   t   selfR   R   R   R   R#   R.   R   t   _fp(    (   R   s0   lib/python2.7/site-packages/matplotlib/quiver.pyR      s:    										c         C` s9   |  j  j j j j |  j  d |  _ t j j	 |   d S(   u,   
        Overload the remove method
        N(
   R   R$   R%   R(   t
   disconnectR*   R
   R   R   t   remove(   R7   (    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyR:   "  s    	c         C` sp  t  rl|  j j s" |  j j   n  |  j   |  j j } |  j |  j |  j _ |  j j } t j	 |  j _ |  j j
 t j |  j g  t j d  |  j  |  _ | |  j _ | |  j _ |  j j } | j |  j  t j |  j d |  j |  j f g d |  j   | |  _ |  j d  k	 r1|  j j |  j  n  |  j j |  j j    |  j j |  j    t  |  _ n  d  S(   Ni   t   offsetst   transOffset(   i   (    t   TrueR   R   t   _initt   _set_transformt   pivotR+   t   UmaskR   t   nomaskt   _make_vertst   npt   arrayR   t   zerosR    t   vertst   polykwt   updateR.   t   mcollectionst   PolyCollectionR   R   t   get_transformt   vectorR"   R
   R5   t   set_transformt
   set_figuret
   get_figure(   R7   t   _pivott   _maskR.   (    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyR>   -  s2    
		c         C` s<   |  j  d k r | |  j S|  j  d k r4 | |  j S| Sd  S(   Nu   Eu   W(   R+   R   (   R7   t   x(    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyt   _text_xI  s
    c         C` s<   |  j  d k r | |  j S|  j  d k r4 | |  j S| Sd  S(   Nu   Nu   S(   R+   R   (   R7   t   y(    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyt   _text_yQ  s
    c         C` s   |  j    |  j j |  |  j   j |  j |  j f  \ } } |  j j |  j	 |   |  j j
 |  j |   |  j j |  t |  _ d  S(   N(   R>   RM   t   drawRL   t   transform_pointR   R   R   t   set_xRT   t   set_yRV   R   t   stale(   R7   t   rendererRS   RU   (    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyRW   Y  s    
'c         C` s   |  j  d k r( |  j |  j j j  n |  j  d k rP |  j |  j j j  nb |  j  d k r{ |  j |  j j j j  n7 |  j  d k r |  j |  j j j j  n t	 d   d  S(   Nu   datau   axesu   figureu   inchesu   unrecognized coordinates(
   R!   RN   R   R$   t	   transDatat	   transAxesR%   t   transFiguret   dpi_scale_transt
   ValueError(   R7   (    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyR?   c  s    c         C` s'   t  j j |  |  |  j j |  d  S(   N(   R   R   RO   R   (   R7   R   (    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyRO   o  s    c         C` s@   |  j  j |  d s, |  j j |  d r6 t i  f St i  f S(   Ni    (   R   t   containsRM   R=   R   (   R7   t
   mouseevent(    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyRb   s  s    
(   t   __name__t
   __module__t   __doc__R1   R2   R@   R   R:   t   _quiverkey_docR>   RT   RV   R   RW   R?   RO   Rb   t   quiverkey_doc(    (    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyR	      s   """	-						
			c    
      G` s  d  g d \ } } } } } t |   }  t |   d k sL t |   d k rg t j |  j d   } n  t j |  j d   } t j |  j d   } | j d k r d | j d } } n | j \ } } t |   d k rgg  |  D] } t j |  j	   ^ q \ } } t |  | k rt |  | k rg  t j
 | |  D] } | j	   ^ qC\ } } qnL t j
 t j |  t j |   }	 g  |	 D] } t j	 |  ^ q\ } } | | | | | f S(   Ni   i   ii   i    i   (   R
   t   listt   lenRD   t
   atleast_1dR   t   ndimt   shapeRE   t   ravelt   meshgridt   arange(
   t   argsR   R   R   t   Vt   Ct   nrt   nct   at	   indexgrid(    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyt   _parse_args  s     $.$7$(c          G` s;   t  d   |  D  } t |  d k r7 t d   n  d  S(   Nc         s` s   |  ] } | j  Vq d  S(   N(   Rm   (   t   .0Rv   (    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pys	   <genexpr>  s    i   u0   The shapes of the passed in arrays do not match.(   t   setRj   Ra   (   t   arrayst
   all_shapes(    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyt   _check_consistent_shapes  s    t   Quiverc           B` s   e  Z d  Z d Z e j e  d    Z d   Z d   Z	 d   Z
 e d	    Z d d
  Z d   Z d   Z d d  Z d   Z d   Z e Z RS(   ur  
    Specialized PolyCollection for arrows.

    The only API method is set_UVC(), which can be used
    to change the size, orientation, and color of the
    arrows; their locations are fixed when the class is
    instantiated.  Possibly this method will be useful
    in animations.

    Much of the work in this class is done in the draw()
    method so that as much information as possible is available
    about the plot.  In subsequent draw() calls, recalculation
    is limited to things that might have changed, so there
    should be no performance penalty from putting the calculations
    in the draw() method.
    u   tailu   midu   middleu   tipc      
   ` s  | |  _  t |   \ } } } } } | |  _ | |  _ t j | d d  t j f | d d  t j f f  |  _ t |  |  _	 | j
 d d  |  _ | j
 d d  |  _ t | j
 d d   |  _ | j
 d d  |  _ | j
 d	 d
  |  _ | j
 d d
  |  _ | j
 d d  |  _ | j
 d d  |  _ | j
 d d  |  _ | j
 d d  |  _ | j
 d d  |  _ | j
 d d  j   }	 |	 |  j k rt d j d |  j d |	    n  |	 d k rd }	 n  |	 |  _ | j
 d | j  |  _ | j d |  j  | j d d#  t  j! j" |  g  d |  j d |  j d  t# | | |  _$ |  j% | | |  t# |  _& d |  _' d |  _( t) j* |       f d!   }
 |  j  j+ j, j- d" |
  |  _. d S($   u   
        The constructor takes one required argument, an Axes
        instance, followed by the args and kwargs described
        by the following pylab interface documentation:
        %s
        Nu   scaleu	   headwidthi   u
   headlengthi   u   headaxislengthg      @u   minshafti   u	   minlengthu   unitsu   widthu   scale_unitsu   anglesu   uvu   coloru   ku   pivotu   tailu-   pivot must be one of {keys}, you passed {inp}t   keyst   inpu   midu   middleu	   transformu
   facecolorsu
   linewidthsi    R;   R<   t   closedc         ` s.       } | d  k	 r* t | _ t | _ n  d  S(   N(   R
   R=   t   _new_UVR   R   (   R   R   (   R   (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyR     s    		u   dpi_changed(   i    (/   R$   Rx   R   R   RD   t   hstackt   newaxist   XYRj   t   NR   R
   t   scalet	   headwidtht   floatt
   headlengtht   headaxislengtht   minshaftt	   minlengtht   unitst   scale_unitst   anglest   widthR"   t   lowert   _PIVOT_VALSRa   t   formatR@   R]   t	   transformt
   setdefaultRJ   RK   R   R   RH   t   set_UVCR   t   keyvect   keytextR&   R'   R%   R(   R)   R*   (   R7   R$   Rq   R.   R   R   R   Rr   Rs   R@   R   (    (   R   s0   lib/python2.7/site-packages/matplotlib/quiver.pyR     sR    			>								
c         C` s6   |  j  j j j |  j  d |  _ t j j |   d S(   u,   
        Overload the remove method
        N(	   R$   R%   R(   R9   R*   R
   RJ   RK   R:   (   R7   (    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyR:     s    	c         C` s   t  r |  j   } |  j } | j   j | j j | j j f  \ } } | |  _ |  j d k r t
 j t j |  j  d d  } d |  j | |  _ n  |  j r |  j d k r |  j |  j |  j |  j  n  t  |  _ n  d S(   u]   
        Initialization delayed until first draw;
        allow time for axes setup.
        i   i   gQ?N(   R=   R?   R$   t   invertedRX   t   bboxR   t   heightt   spanR
   RD   t   clipt   matht   sqrtR   R   R   RC   R   Rr   R   (   R7   t   transR$   t   sxt   syt   sn(    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyR>      s    	!	!c         C` sb   |  j    } |  j   } | | | | } | j |  j  } t j j   } | j | d t | S(   Nt   ignore(	   RL   t   get_offset_transformR   R   t
   transformst   Bboxt   nullt   update_from_data_xyR=   (   R7   R]   R   R<   t   full_transformR   R   (    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyt   get_datalim  s    c         C` sd   |  j    |  j |  j |  j |  j  } |  j | d t t |  _ t j	 j
 |  |  t |  _ d  S(   NR   (   R>   RC   R   Rr   R   t	   set_vertsR   R   RJ   RK   RW   R[   (   R7   R\   RG   (    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyRW      s    
	c         C` s=  t  j | d t j   } t  j | d t j   } t  j | j | j d t d t } | d  k	 r t  j | d t j   } t  j | | j d t d t } | t  j k r | j	   } q t  j
 | d | d t } n  | j	 d  |  _ | j	 d  |  _ | |  _ | d  k	 r'|  j |  n  t |  _ t |  _ d  S(   Nt   copyt   shrinkt   maski   (   R   t   masked_invalidR=   Rn   t   mask_orR   R   R
   RB   t   filledRE   R   Rr   RA   t	   set_arrayR   R[   (   R7   R   Rr   Rs   R   (    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyR   )  s     $!		c   
      C` s:  |  j  } | d
 k r | d k r< | j j } | j j } n{ | d k rc | j j } | j j } nT | j j } | j j } | j j } | j j } t j | |  } t j | |  } | | }	 nr | d k r | j j }	 nW | d k r | j j }	 n< | d k rd }	 n' | d k r*| j j }	 n t	 d	   |	 S(   uK   
        Return a scale factor for converting from units to pixels
        u   xu   yu   xyu   widthu   heightu   dotsg      ?u   inchesu   unrecognized units(   u   xu   yu   xy(
   R$   t   viewLimR   R   R   RD   t   hypotR%   R   Ra   (
   R7   R   R$   t   dx0t   dx1t   dxx0t   dxx1t   dyy0t   dyy1t   dx(    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyt   _dots_per_unit>  s2    		c         C` sA   |  j  |  j  } | |  _ t j   j |  } |  j |  | S(   uf   
        Sets the PolygonCollection transform to go
        from arrow width units to pixels.
        (   R   R   t   _trans_scaleR   t   Affine2DR   RN   (   R7   R   R   (    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyR?   _  s
    	i   c   
      C` s   |  j  j j |  j  } t j | d  d   t j f | d  d   t j f f  } |  j  j j |  j | |  } | | } t j | d  d   d f | d  d   d f  } t j | j	   | }	 | |	 f S(   Ni   i    (
   R$   R]   R   R   RD   R   R   t   arctan2R   t   T(
   R7   R   Rr   t   epst   xyt   uvt   xypt   dxyR   t   lengths(    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyt   _angles_lengthsj  s    ; 
2c         C` s$  | | d } t  | t j  r& | n d } | d k rh |  j d k rh |  j | | d d \ } } n^ | d k s |  j d k r t j |  j j j	  j
   d } |  j | | d | \ } } n  | r |  j d k r | } n t j |  } |  j d  k rjt
 d t j |  j   }	 |  j t j k	 rF| |  j j   }
 n | j   }
 d |
 |	 |  j } n  |  j d  k r|  j d  k r| |  _ n  d	 } nV |  j d k rd } n |  j |  j  } | |  j } |  j d  k r| | |  _ n  | | |  j |  j } |  j |  \ } } | d k r5| } n? | d
 k rSt j |  } n! t j t j |   j d  } | j d  } | | d t j d |  |  j } | d  d   d  d   t j f } t j  | j! | j" f d d } |  j t j k	 r t j# |  } t j$ | |  j <n  | S(   Ny              ?u    u   xyR   i   gMbP?i
   g?g      ?u   uvi    it   axisi   (   ii   (%   t
   isinstancet   sixt   string_typesR   R   RD   t   absR$   t   dataLimt   extentst   maxR   R
   R   R   R   RA   R   RB   t   meanR   R   R   R   t	   _h_arrowsR    R   t   deg2radR   t   reshapet   expR   t   concatenatet   realt   imagRE   t   masked(   R7   R   Rr   R   R   t
   str_anglesR   R   Rv   R   t   ameanR   t   widthu_per_lenuR   t   lengthR   R   t   thetaR   R   (    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyRC   s  sR    !"!				!&"!c         C` s  |  j  |  j } t |  } | j | d  } t j | d d d | t j d |  j |  j d g t j  } | t j d d d d g  | } d t j d d |  j	 d g t j  } t j
 | t j d d  f | d d } t j d | |  j | |  j | g t j  } d t j d d |  j	 d g t j  } d d d d	 d d d d g } | j | d  }	 | j | d  }
 |
 d d  d	 d
  f c d
 9<| j |  } | j |  } | d	 d
 c !d
 9+| d k r| | n d } | | t j d d  f } | | t j d d  f } t j
 | | k  d d d } t j |	 | d | t j |
 | d | |  j d k r|	 d |	 d d  d	 t j f 8}	 n\ |  j d k r|	 |	 d d  d	 t j f }	 n* |  j d k rt d j |  j    n  | |  j k  } | j   rt j d d d t j  t j d } t j |  |  j d } t j |  |  j d } t j
 | t j d d  f | d d } t j
 | t j d d  f | d d } t j
 | d d  } t j |	 | d | t j |
 | d | n  |	 |
 f S(   u     length is in arrow width units i   i    i   i   t   outg      ?NR   i   ig        i   t   whereu   middleu   tipu   tailuC   Quiver.pivot must have value in {{'middle', 'tip', 'tail'}} not {0}g      @i   (   R   R   Rj   R   RD   R   RE   R   t   float64R   t   repeatR   t   taket   copytoR@   Ra   R   R   t   anyRp   t   pit   cost   sin(   R7   R   t   minshR   RS   RU   t   x0t   y0t   iiR   R   t   X0t   Y0R   t   shortt   tooshortt   tht   x1t   y1t   X1t   Y1(    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyR     sX    #(+("'#	&++(   u   tailu   midu   middleu   tipN(   Rd   Re   Rf   R   R   t   Substitutiont   _quiver_docR   R:   R>   R   R   RW   R
   R   R   R?   R   RC   R   t
   quiver_doc(    (    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyR~     s   C	
					!			;	=u  
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:

  *length*:
    Length of the barb in points; the other parts of the barb
    are scaled against this.
    Default is 7.

  *pivot*: [ 'tip' | 'middle' | float ]
    The part of the arrow that is at the grid point; the arrow rotates
    about this point, hence the name *pivot*.  Default is 'tip'. Can
    also be a number, which shifts the start of the barb that many
    points from the origin.

  *barbcolor*: [ color | color sequence ]
    Specifies the color all parts of the barb except any flags.  This
    parameter is analogous 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
    analogous 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.

  *sizes*:
    A dictionary of coefficients specifying the ratio of a given
    feature to the length of the barb. Only those values one wishes to
    override need to be included.  These features include:

        - 'spacing' - space between features (flags, full/half barbs)

        - 'height' - height (distance from shaft to top) of a flag or
          full barb

        - 'width' - width of a flag, twice the width of a full barb

        - 'emptybarb' - radius of the circle used for low magnitudes

  *fill_empty*:
    A flag on whether the empty barbs (circles) that are drawn should
    be filled with the flag color.  If they are not filled, they will
    be drawn such that no color is applied to the center.  Default is
    False

  *rounding*:
    A flag to indicate whether the vector magnitude should be rounded
    when allocating barb components.  If True, the magnitude is
    rounded to the nearest multiple of the half-barb increment.  If
    False, the magnitude is simply truncated to the next lowest
    multiple.  Default is True

  *barb_increments*:
    A dictionary of increments specifying values to associate with
    different parts of the barb. Only those values one wishes to
    override need to be included.

        - 'half' - half barbs (Default is 5)

        - 'full' - full barbs (Default is 10)

        - 'flag' - flags (default is 50)

  *flip_barb*:
    Either a single boolean flag or an array of booleans.  Single
    boolean indicates whether the lines and flags should point
    opposite to normal for all barbs.  An array (which should be the
    same size as the other data arrays) indicates whether to flip for
    each individual barb.  Normal behavior is for the barbs and lines
    to point right (comes from wind barbs having these features point
    towards low pressure in the Northern Hemisphere.)  Default is
    False

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::

 :     /\    \\
 :    /  \    \\
 :   /    \    \    \\
 :  /      \    \    \\
 : ------------------------------

.. note the double \\ at the end of each line to make the figure
.. render correctly

The largest increment is given by a triangle (or "flag"). After those
come full lines (barbs). The smallest increment is a half line.  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, using the
standard increments of 50, 10, and 5.

linewidths and edgecolors can be used to customize the barb.
Additional :class:`~matplotlib.collections.PolyCollection` keyword
arguments:

%(PolyCollection)s
t	   barbs_doct   Barbsc           B` sk   e  Z d  Z e j d    Z e d d d d  Z d   Z d	 d  Z
 d   Z e j j j e _ e Z RS(
   u>  
    Specialized PolyCollection for barbs.

    The only API method is :meth:`set_UVC`, which can be used to
    change the size, orientation, and color of the arrows.  Locations
    are changed using the :meth:`set_offsets` collection method.
    Possibly this method will be useful in animations.

    There is one internal function :meth:`_find_tails` which finds
    exactly what should be put on the barb given the vector magnitude.
    From there :meth:`_make_barbs` is used to find the vertices of the
    polygon to represent the barb based on this information.
    c      	   O` s+  | j  d d  |  _ | j  d d  |  _ | j  d d  } | j  d d  } | j  d t    |  _ | j  d t  |  _ | j  d	 t    |  _ | j  d
 t	  |  _
 | j  d t  |  _ | j  d | j  } d | | f k r'd | d <| r| | d <q;| r| | d <q;| j d d  n | | d <| | d <d | k r`d | k r`d | d <n  t |   \ } } }	 }
 } | |  _ | |  _ t j | d d  t j f | d d  t j f f  } |  j d d } t j j |  g  | f d | d | | |  j t j    |  j |	 |
 |  d S(   u   
        The constructor takes one required argument, an Axes
        instance, followed by the args and kwargs described
        by the following pylab interface documentation:
        %(barbs_doc)s
        u   pivotu   tipu   lengthi   u	   barbcoloru	   flagcoloru   sizesu
   fill_emptyu   barb_incrementsu   roundingu	   flip_barbu	   transformu   faceu
   edgecolorsu
   facecolorsu   ku	   linewidthu   lwi   Ni   i   R;   R<   (   R   RQ   t   _lengthR
   R-   t   sizesR   t
   fill_emptyt   barb_incrementsR=   t   roundingt   flipR]   R   Rx   RS   RU   RD   R   R   RJ   RK   R   RN   R   t   IdentityTransformR   (   R7   R$   Rq   R.   t	   barbcolort	   flagcolorR   RS   RU   t   ut   vt   cR   t	   barb_size(    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyR     s>    


		;
i   i
   i2   c   
      C` s   | r$ | | | d j  t  } n  t j | |  j  t  } t j | |  } t j | |  j  t  } t j | |  } | | k } | | d k B| d k B}	 | | | |	 f S(   uZ  
        Find how many of each of the tail pieces is necessary.  Flag
        specifies the increment for a flag, barb for a full barb, and half for
        half a barb. Mag should be the magnitude of a vector (i.e., >= 0).

        This returns a tuple of:

            (*number of flags*, *number of barbs*, *half_flag*, *empty_flag*)

        *half_flag* is a boolean whether half of a barb is needed,
        since there should only ever be one half on a given
        barb. *empty_flag* flag is an array of flags to easily tell if
        a barb is empty (too low to plot any barbs/flags.
        g      ?i    (   t   astypet   intRD   t   floort   mod(
   R7   t   magR   t   halft   fullt   flagt	   num_flagst   num_barbt	   half_flagt
   empty_flag(    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyt   _find_tails  s    c         C` s  | |	 j  d d  } | |	 j  d d  } | |	 j  d d  } | |	 j  d d  } t d	 d
 d | d  } | r | } n  d
 } y t |  } Wn! t k
 r | | j   } n Xt j | |  t j d } t	 d d | j
   } |
 r| } n" t j | | d d d  f  } g  } xt j |  D]\ } } | | rb| j |  q9n  | | f g } | } x t | |  D]u } | | k r| | d 7} n  | j | | | g | | | | d | g | | | | g g  | | | 8} qWxb t | |  D]P } | j | | | f | | | | | d f | | | f g  | | 8} qW| | r| | k r| j | | | f  | d | 8} n  | j | | | f | | d | | | d f | | | f g  n  t j   j |  j |  } | j |  q9W| S(   u  
        This function actually creates the wind barbs.  *u* and *v*
        are components of the vector in the *x* and *y* directions,
        respectively.

        *nflags*, *nbarbs*, and *half_barb*, empty_flag* are,
        *respectively, the number of flags, number of barbs, flag for
        *half a barb, and flag for empty barb, ostensibly obtained
        *from :meth:`_find_tails`.

        *length* is the length of the barb staff in points.

        *pivot* specifies the point on the barb around which the
        entire barb should be rotated.  Right now, valid options are
        'tip' and 'middle'. Can also be a number, which shifts the start
        of the barb that many points from the origin.

        *sizes* is a dictionary of coefficients specifying the ratio
        of a given feature to the length of the barb. These features
        include:

            - *spacing*: space between features (flags, full/half
               barbs)

            - *height*: distance from shaft of top of a flag or full
               barb

            - *width* - width of a flag, twice the width of a full barb

            - *emptybarb* - radius of the circle used for low
               magnitudes

        *fill_empty* specifies whether the circle representing an
        empty barb should be filled or not (this changes the drawing
        of the polygon).

        *flip* is a flag indicating whether the features should be flipped to
        the other side of the barb (useful for winds in the southern
        hemisphere).

        This function returns list of arrays of vertices, defining a polygon
        for each of the wind barbs.  These polygons have been rotated to
        properly align with the vector direction.
        u   spacingg      ?u   heightg?u   widthg      ?u	   emptybarbg333333?t   tipg        t   middleg       @i   i    t   radiusNig      ?i   (   i    i    (   t   getR-   R   Ra   R   R   R   RD   R   R   t	   get_vertsR   t   ndenumeratet   appendt   ranget   extendR   R   t   rotateR   (   R7   R  R  t   nflagst   nbarbst	   half_barbR  R   R@   R   R   R  t   spacingt   full_heightt
   full_widtht	   empty_radt   pivot_pointst   endxt   endyR   t   circt
   empty_barbt	   barb_listt   indexR    t
   poly_vertst   offsett   i(    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyt   _make_barbs  sd    1
	"

	c         C` s  t  j | d t j   |  _ t  j | d t j   |  _ | d  k	 r t  j | d t j   } t |  j j   |  j	 j   |  j |  j |  \ } } } } } t
 | | | | |  nL t |  j j   |  j	 j   |  j |  j  \ } } } } t
 | | | |  t j | |  }	 |  j |	 |  j |  j  \ }
 } } } |  j | | |
 | | | |  j |  j |  j |  j |  j  } |  j |  | d  k	 r|  j |  n  t j | d  d   t j f | d  d   t j f f  } | |  _ t |  _ d  S(   NR   (   R   R   R   Rn   R  R  R
   R   RS   RU   R}   RD   R   R  R   R   R1  R   RQ   R   R   R  R   R   R   R   t   _offsetsR=   R[   (   R7   R   Rr   Rs   R  RS   RU   R  R  t	   magnitudet   flagst   barbst   halvest   emptyt
   plot_barbsR   (    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyR   w  s0    $	;	c         C` s   | d d  d f |  _  | d d  d f |  _ t |  j  j   |  j j   |  j |  j  \ } } } } t | | | |  t j | d d  t j	 f | d d  t j	 f f  } t
 j j |  |  t |  _ d S(   u  
        Set the offsets for the barb polygons.  This saves the offsets passed
        in and actually sets version masked as appropriate for the existing
        U/V data. *offsets* should be a sequence.

        ACCEPTS: sequence of pairs of floats
        Ni    i   (   RS   RU   R   Rn   R  R  R}   RD   R   R   RJ   RK   t   set_offsetsR=   R[   (   R7   R   RS   RU   R  R  (    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyR9    s    ;N(   Rd   Re   Rf   R   t   interpdR   R=   R  R1  R
   R   R9  RJ   RK   t
   _barbs_docR   (    (    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyR   |  s   9 	#	(-   Rf   t
   __future__R    R   R   R   R   R   R&   t   numpyRD   R   t   matplotlib.collectionst   collectionsRJ   t   matplotlib.transformsR   t   matplotlib.textR   R/   t   matplotlib.artistt   artistR   R   t
   matplotlibR   t   matplotlib.font_managerR3   t   matplotlib.cbookR   t   matplotlib.patchesR   R:  t   paramsR   Rg   R   R	   Rx   R}   RK   R~   R;  RI   R   (    (    (    s0   lib/python2.7/site-packages/matplotlib/quiver.pyt   <module>   s2   "A		 