3
ƽhE                @   s  d dl Z d dlZd dlZd dlZd dlmZ d dlZd dlZd dl	Z
ddlmZmZmZmZmZmZ ddlmZmZmZmZmZmZmZmZ ddlmZ ejdgdgd	gd
gdgdG dd dejZ ej!e Z"xdFD ]Z#ej$j%e#e"i qW ej&e j' G dd de Z(G dd de Z)G dd de Z*G dd de Z+G d d de Z,G d!d de Z-G d"d de Z.G d#d de,Z/ej$j%d$j0ej1e/j'j2 d%d d& G d'd de*Z3G d(d de Z4G d)d de4Z5G d*d de4Z6dGd,d-Z7dHd/d0Z8d1d2 Z9G d3d4 d4Z:dIdd5d6d7Z;G d8d9 d9e:Z<G d:d; d;e:Z=d<d= Z>G d>d? d?e:Z?ej$j%e<j@ e9e<jAe?j@ e=j@ d@ ej&e< ej&e? ej&e= G dAd de ZBG dBdC dCe ZCG dDdE dEeCZDdS )J    N)Number   )artistcbookcolors	docstringlines
transforms)NonIntersectingPathExceptionget_cos_singet_intersectionget_parallelsinside_circlemake_wedged_bezier2)split_bezier_intersecting_with_closedpathsplit_path_inout)PathaaZecZfclslw)antialiased	edgecolor	facecolor	linestyle	linewidthc            
       s  e Zd ZdZdZejjZejjZdZ	dRddZ
dd	 Zd
d ZdSddZdTddZdUddZdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Z fd2d3Z d4d5 Z!d6d7 Z"d8d9 Z#d:d; Z$e%e$e#Z&d<d= Z'd>d? Z(d@dA Z)dBdC Z*dDdE Z+dFdG Z,e-j.dHdI Z/e0j1dJdK Z2dLdM Z3dVdNdOZ4dPdQ Z5  Z6S )WPatchz
    A patch is a 2D artist with a face color and an edge color.

    If any of *edgecolor*, *facecolor*, *linewidth*, or *antialiased*
    are *None*, they default to their rc params setting.
    r   FNTc             K   s  t jj|  |dkrtjd }|dkr*d}|	dkr6d}	|
dkrBd}
|dkrTtjd }tjtjd | _d| _|dk	r|dk	s|dk	rt	j
d	 | j| n| j| | j| d| _d
| _| j| | j| | j| | j| | j| | j|	 | j|
 t|r| j| dS )zQ
        The following kwarg properties are supported

        %(Patch)s
        Nzpatch.linewidthsolidZbuttZmiterzpatch.antialiasedzhatch.colorTzQSetting the 'color' property will override the edgecolor or facecolor properties.r   )r   Artist__init__mplrcParamsr   to_rgba_hatch_color_fillr   Z_warn_external	set_colorset_edgecolorset_facecolor
_us_dashes
_linewidthset_fillset_linestyleset_linewidthset_antialiased	set_hatchset_capstyleset_joinstylelenupdate)selfr   r   colorr   r   r   hatchfillcapstyle	joinstylekwargs r9   8/tmp/pip-build-7iwl8md4/matplotlib/matplotlib/patches.pyr   )   s>    











zPatch.__init__c             C   s.   | j  }| j }|j|}t|r*|d S g S )z
        Return a copy of the vertices used in this patch.

        If the patch contains Bezier curves, the curves will be interpolated by
        line segments.  To access the curves as curves, use `get_path`.
        r   )get_transformget_pathZto_polygonsr0   )r2   transpathZpolygonsr9   r9   r:   	get_vertsa   s    
zPatch.get_vertsc             C   sB   |d k	r|S t | jtr | j}n| j d dkr6d}n| j }|S )N   r   )
isinstanceZ_pickerr   get_edgecolorget_linewidth)r2   radius_radiusr9   r9   r:   _process_radiuso   s    zPatch._process_radiusc       	         s   j  \}}|dk	r||fS jj j}|dk	rj j}tj|tjk\}|dd }t	ttj
||tj
||}n
j g}t fdd|D }|i fS )z
        Test whether the mouse event occurred in the patch.

        Returns
        -------
        (bool, empty dict)
        Nr   c             3   s(   | ] }|j  j jfj V  qd S )N)contains_pointxyr;   ).0subpath)
mouseeventrD   r2   r9   r:   	<genexpr>   s   z!Patch.contains.<locals>.<genexpr>)Z_default_containsrF   r<   codesverticesnpwherer   MOVETOmapsplitany)	r2   rL   rD   insideinforN   rO   ZidxsZsubpathsr9   )rL   rD   r2   r:   contains{   s     




zPatch.containsc             C   s    | j |}| j j|| j |S )a@  
        Return whether the given point is inside the patch.

        Parameters
        ----------
        point : (float, float)
            The point (x, y) to check, in target coordinates of
            ``self.get_transform()``. These are display coordinates for patches
            that are added to a figure or axes.
        radius : float, optional
            Add an additional margin on the patch in target coordinates of
            ``self.get_transform()``. See `.Path.contains_point` for further
            details.

        Returns
        -------
        bool

        Notes
        -----
        The proper use of this method depends on the transform of the patch.
        Isolated patches do not have a transform. In this case, the patch
        creation coordinates and the point coordinates match. The following
        example checks that the center of a circle is within the circle

        >>> center = 0, 0
        >>> c = Circle(center, radius=1)
        >>> c.contains_point(center)
        True

        The convention of checking against the transformed patch stems from
        the fact that this method is predominantly used to check if display
        coordinates (e.g. from mouse events) are within the patch. If you want
        to do the above check with data coordinates, you have to properly
        transform them first:

        >>> center = 0, 0
        >>> c = Circle(center, radius=1)
        >>> plt.gca().add_patch(c)
        >>> transformed_center = c.get_transform().transform(center)
        >>> c.contains_point(transformed_center)
        True

        )rF   r<   rG   r;   )r2   ZpointrD   r9   r9   r:   rG      s    -

zPatch.contains_pointc             C   s    | j |}| j j|| j |S )a  
        Return whether the given points are inside the patch.

        Parameters
        ----------
        points : (N, 2) array
            The points to check, in target coordinates of
            ``self.get_transform()``. These are display coordinates for patches
            that are added to a figure or axes. Columns contain x and y values.
        radius : float, optional
            Add an additional margin on the patch in target coordinates of
            ``self.get_transform()``. See `.Path.contains_point` for further
            details.

        Returns
        -------
        length-N bool array

        Notes
        -----
        The proper use of this method depends on the transform of the patch.
        See the notes on `.Patch.contains_point`.
        )rF   r<   contains_pointsr;   )r2   pointsrD   r9   r9   r:   rY      s    

zPatch.contains_pointsc             C   sv   t jj| | |j| _|j| _|j| _|j| _|j| _|j| _|j	| _	|j
| _
| j|j | j|j  |j | _d S )N)r   r   update_from
_edgecolor
_facecolor_original_edgecolor_original_facecolorr#   _hatchr"   r'   r+   r(   set_transformget_data_transformZis_transform_setZ_transformSet)r2   otherr9   r9   r:   r[      s    zPatch.update_fromc             C   s   | j  j| j S )zU
        Return the `Patch`'s axis-aligned extents as a `~.transforms.Bbox`.
        )r<   get_extentsr;   )r2   r9   r9   r:   rd      s    zPatch.get_extentsc             C   s   | j  tjj|  S )z;Return the `~.transforms.Transform` applied to the `Patch`.)get_patch_transformr   r   r;   )r2   r9   r9   r:   r;     s    zPatch.get_transformc             C   s   t jj| S )zo
        Return the `~.transforms.Transform` mapping data coordinates to
        physical coordinates.
        )r   r   r;   )r2   r9   r9   r:   rb     s    zPatch.get_data_transformc             C   s   t j S )aS  
        Return the `~.transforms.Transform` instance mapping patch coordinates
        to data coordinates.

        For example, one may define a patch of a circle which represents a
        radius of 5 by providing coordinates for a unit circle, and a
        transform which scales the coordinates (the patch coordinate) by 5.
        )r	   IdentityTransform)r2   r9   r9   r:   re     s    	zPatch.get_patch_transformc             C   s   | j S )z0Return whether antialiasing is used for drawing.)_antialiased)r2   r9   r9   r:   get_antialiased  s    zPatch.get_antialiasedc             C   s   | j S )zReturn the edge color.)r\   )r2   r9   r9   r:   rB     s    zPatch.get_edgecolorc             C   s   | j S )zReturn the face color.)r]   )r2   r9   r9   r:   get_facecolor   s    zPatch.get_facecolorc             C   s   | j S )z Return the line width in points.)r(   )r2   r9   r9   r:   rC   $  s    zPatch.get_linewidthc             C   s   | j S )zReturn the linestyle.)
_linestyle)r2   r9   r9   r:   get_linestyle(  s    zPatch.get_linestylec             C   s"   |dkrt jd }|| _d| _dS )z{
        Set whether to use antialiased rendering.

        Parameters
        ----------
        b : bool or None
        Nzpatch.antialiasedT)r   r    rg   stale)r2   r   r9   r9   r:   r,   ,  s    
zPatch.set_antialiasedc             C   s^   d}|d kr8t jd s$| j s$| jr0t jd }nd}d}tj|| j| _|rT| j| _d| _	d S )NTzpatch.force_edgecolorzpatch.edgecolornoneF)
r   r    r#   _edge_defaultr   r!   _alphar\   r"   rl   )r2   r3   set_hatch_colorr9   r9   r:   _set_edgecolor9  s    
zPatch._set_edgecolorc             C   s   || _ | j| dS )zz
        Set the patch edge color.

        Parameters
        ----------
        color : color or None or 'auto'
        N)r^   rq   )r2   r3   r9   r9   r:   r%   H  s    zPatch.set_edgecolorc             C   s:   |d krt jd }| jr| jnd}tj||| _d| _d S )Nzpatch.facecolorr   T)r   r    r#   ro   r   r!   r]   rl   )r2   r3   alphar9   r9   r:   _set_facecolorS  s
    
zPatch._set_facecolorc             C   s   || _ | j| dS )zp
        Set the patch face color.

        Parameters
        ----------
        color : color or None
        N)r_   rs   )r2   r3   r9   r9   r:   r&   Z  s    zPatch.set_facecolorc             C   s   | j | | j| dS )a  
        Set both the edgecolor and the facecolor.

        Parameters
        ----------
        c : color

        See Also
        --------
        Patch.set_facecolor, Patch.set_edgecolor
            For setting the edge or face color individually.
        N)r&   r%   )r2   cr9   r9   r:   r$   e  s    
zPatch.set_colorc                s(   t  j| | j| j | j| j d S )N)super	set_alphars   r_   rq   r^   )r2   rr   )	__class__r9   r:   rv   u  s    zPatch.set_alphac             C   sZ   |dkr$t jd }|dkr$t jd }t|| _| j\}}tj||| j\| _| _d| _	dS )zu
        Set the patch linewidth in points.

        Parameters
        ----------
        w : float or None
        Nzpatch.linewidthzaxes.linewidthT)
r   r    floatr(   r'   mlines_scale_dashes_dashoffset_dashesrl   )r2   woffsetr   r9   r9   r:   r+   |  s    



zPatch.set_linewidthc             C   sH   |dkrd}|| _ tj| \}}| _tj||| j\| _| _d| _dS )a  
        Set the patch linestyle.

        ===========================   =================
        linestyle                     description
        ===========================   =================
        ``'-'`` or ``'solid'``        solid line
        ``'--'`` or  ``'dashed'``     dashed line
        ``'-.'`` or  ``'dashdot'``    dash-dotted line
        ``':'`` or ``'dotted'``       dotted line
        ===========================   =================

        Alternatively a dash tuple of the following form can be provided::

            (offset, onoffseq)

        where ``onoffseq`` is an even length tuple of on and off ink in points.

        Parameters
        ----------
        ls : {'-', '--', '-.', ':', '', (offset, on-off-seq), ...}
            The line style.
        Nr   T)	rj   ry   Z_get_dash_patternr'   rz   r(   r{   r|   rl   )r2   r   r~   r9   r9   r:   r*     s    zPatch.set_linestylec             C   s,   t || _| j| j | j| j d| _dS )zh
        Set whether to fill the patch.

        Parameters
        ----------
        b : bool
        TN)boolr#   rs   r_   rq   r^   rl   )r2   br9   r9   r:   r)     s    
zPatch.set_fillc             C   s   | j S )z#Return whether the patch is filled.)r#   )r2   r9   r9   r:   get_fill  s    zPatch.get_fillc             C   s   t jj| || _d| _dS )zv
        Set the capstyle.

        Parameters
        ----------
        s : {'butt', 'round', 'projecting'}
        TN)r   rcsetupZvalidate_capstyle	_capstylerl   )r2   sr9   r9   r:   r.     s    zPatch.set_capstylec             C   s   | j S )zReturn the capstyle.)r   )r2   r9   r9   r:   get_capstyle  s    zPatch.get_capstylec             C   s   t jj| || _d| _dS )zs
        Set the joinstyle.

        Parameters
        ----------
        s : {'miter', 'round', 'bevel'}
        TN)r   r   Zvalidate_joinstyle
_joinstylerl   )r2   r   r9   r9   r:   r/     s    zPatch.set_joinstylec             C   s   | j S )zReturn the joinstyle.)r   )r2   r9   r9   r:   get_joinstyle  s    zPatch.get_joinstylec             C   s   || _ d| _dS )a  
        Set the hatching pattern.

        *hatch* can be one of::

          /   - diagonal hatching
          \   - back diagonal
          |   - vertical
          -   - horizontal
          +   - crossed
          x   - crossed diagonal
          o   - small circle
          O   - large circle
          .   - dots
          *   - stars

        Letters can be combined, in which case all the specified
        hatchings are done.  If same letter repeats, it increases the
        density of hatching of that pattern.

        Hatching is supported in the PostScript, PDF, SVG and Agg
        backends only.

        Parameters
        ----------
        hatch : {'/', '\\', '|', '-', '+', 'x', 'o', 'O', '.', '*'}
        TN)r`   rl   )r2   r4   r9   r9   r:   r-     s    zPatch.set_hatchc             C   s   | j S )zReturn the hatching pattern.)r`   )r2   r9   r9   r:   	get_hatch  s    zPatch.get_hatchc             c   s6  |j d| j  |j }|j| jdd | j}| jd dkr@d}|j| |j| j| j	 |j
| j |j| j |j| j | j| |j| j |j| j  |j| j | jr|j| j |j| j | j dk	r|j| j   | j r
ddlm} || j |}t j!|j"|V  |j#  |j$d d| _%dS )	ac  
        ``draw()`` helper factored out for sharing with `FancyArrowPatch`.

        Yields a callable ``dp`` such that calling ``dp(*args, **kwargs)`` is
        equivalent to calling ``renderer1.draw_path(gc, *args, **kwargs)``
        where ``renderer1`` and ``gc`` have been suitably set from ``renderer``
        and the artist's properties.
        patchT)ZisRGBAr@   r   N)PathEffectRendererF)&Z
open_groupZget_gidZnew_gcZset_foregroundr\   r(   r+   Z
set_dashesr{   r|   r.   r   r/   r   r,   rg   Z_set_gc_clipZset_urlZ_urlZset_snapZget_snaprv   ro   r`   r-   rp   r"   Zget_sketch_paramsZset_sketch_paramsZget_path_effectsZmatplotlib.patheffectsr   	functoolspartial	draw_pathZrestoreZclose_grouprl   )r2   renderergcr   r   r9   r9   r:   _bind_draw_path_function  s6    



zPatch._bind_draw_path_functionc             C   s~   | j  sd S tj| ddZ | j|D}| j }| j }|j|}|j }|||| jd r`| jnd  W d Q R X W d Q R X d S )Nr   )r{   r@   )	get_visibler   Z_setattr_cmr   r<   r;   Ztransform_path_non_affineZ
get_affiner]   )r2   r   r   r>   	transformZtpathaffiner9   r9   r:   draw?  s    
z
Patch.drawc             C   s   t ddS )zReturn the path of this patch.zDerived must overrideN)NotImplementedError)r2   r9   r9   r:   r<   Q  s    zPatch.get_pathc             C   s   | j  j| j S )N)r<   rd   r;   )r2   r   r9   r9   r:   get_window_extentU  s    zPatch.get_window_extentc             C   s$   | j |d }| j|d }||fS )z)Convert x and y units for a tuple (x, y).r   r   )convert_xunitsconvert_yunits)r2   xyrH   rI   r9   r9   r:   _convert_xy_unitsX  s    zPatch._convert_xy_units)
NNNNNNNTNN)N)N)N)N)7__name__
__module____qualname____doc__zorderry   ZLine2DZvalidCapZ	validJoinrn   r   r?   rF   rX   rG   rY   r[   rd   r;   rb   re   rh   rB   ri   rC   rk   r,   rq   r%   rs   r&   r$   rv   r+   r*   r)   r   propertyr5   r.   r   r/   r   r-   r   
contextlibcontextmanagerr   r   allow_rasterizationr   r<   r   r   __classcell__r9   r9   )rw   r:   r      sj            
.

2
"
4
r   	RectangleCircleRegularPolygonPolygonWedgeArrow
FancyArrowCirclePolygonEllipseArcFancyBboxPatchc               @   s   e Zd Zdd ZejddejdddZej	dZ
dd	 Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )Shadowc             C   s   dt | j S )Nz
Shadow(%s))strr   )r2   r9   r9   r:   __str__j  s    zShadow.__str__z3.3propsNc             K   sl   t j|  || _|dkr>dtjtj| jj  }||dd}||| _|| | _	| _
tj | _| j  dS )aP  
        Create a shadow of the given *patch*.

        By default, the shadow will have the same face color as the *patch*,
        but darkened.

        Parameters
        ----------
        patch : `.Patch`
            The patch to create the shadow for.
        ox, oy : float
            The shift of the shadow in data coordinates, scaled by a factor
            of dpi/72.
        props : dict
            *deprecated (use kwargs instead)* Properties of the shadow patch.
        **kwargs
            Properties of the shadow patch. Supported keys are:

            %(Patch)s
        Ng333333?g      ?)r   r   rr   )r   r   r   rP   asarrayr   Zto_rgbri   _props_ox_oyr	   Affine2D_shadow_transform_update)r2   r   oxoyr   r8   r3   r9   r9   r:   r   m  s    


zShadow.__init__c             C   s6   | j | j | jtj| jjtj  | j| j d S )N)	r[   r   Z
set_zorderrP   Z	nextafterr   infr1   r   )r2   r9   r9   r:   r     s    zShadow._updatec             C   s.   |j | j}|j | j}| jj j|| d S )N)points_to_pixelsr   r   r   clear	translate)r2   r   r   r   r9   r9   r:   _update_transform  s    zShadow._update_transformc             C   s   | j S )N)r   )r2   r9   r9   r:   _get_ox  s    zShadow._get_oxc             C   s
   || _ d S )N)r   )r2   r   r9   r9   r:   _set_ox  s    zShadow._set_oxc             C   s   | j S )N)r   )r2   r9   r9   r:   _get_oy  s    zShadow._get_oyc             C   s
   || _ d S )N)r   )r2   r   r9   r9   r:   _set_oy  s    zShadow._set_oyc             C   s
   | j j S )N)r   r<   )r2   r9   r9   r:   r<     s    zShadow.get_pathc             C   s   | j j | j S )N)r   re   r   )r2   r9   r9   r:   re     s    zShadow.get_patch_transformc             C   s   | j | tj| | d S )N)r   r   r   )r2   r   r9   r9   r:   r     s    
zShadow.draw)N)r   r   r   r   r   Z_delete_parameterr   dedent_interpdr   Z_deprecate_privatize_attributer   r   r   r   r   r   r   r<   re   r   r9   r9   r9   r:   r   i  s   
%
r   c               @   s   e Zd ZdZdd Zejd,ddZdd Zd	d
 Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* ZeeeZd+S )-r   a  
    A rectangle defined via an anchor point *xy* and its *width* and *height*.

    The rectangle extends from ``xy[0]`` to ``xy[0] + width`` in x-direction
    and from ``xy[1]`` to ``xy[1] + height`` in y-direction. ::

      :                +------------------+
      :                |                  |
      :              height               |
      :                |                  |
      :               (xy)---- width -----+

    One may picture *xy* as the bottom left corner, but which corner *xy* is
    actually depends on the the direction of the axis and the sign of *width*
    and *height*; e.g. *xy* would be the bottom right corner if the x-axis
    was inverted or if *width* was negative.
    c             C   s$   | j | j| j| j| jf}d}|| S )Nz5Rectangle(xy=(%g, %g), width=%g, height=%g, angle=%g))_x0_y0_width_heightangle)r2   parsfmtr9   r9   r:   r     s    zRectangle.__str__        c             K   sb   t j| f| |d | _|d | _|| _|| _| j| j | _| j| j | _t|| _	t
j | _dS )a  
        Parameters
        ----------
        xy : (float, float)
            The anchor point.
        width : float
            Rectangle width.
        height : float
            Rectangle height.
        angle : float, default: 0
            Rotation in degrees anti-clockwise about *xy*.

        Other Parameters
        ----------------
        **kwargs : `.Patch` properties
            %(Patch)s
        r   r   N)r   r   r   r   r   r   _x1_y1rx   r   r	   rf   _rect_transform)r2   r   widthheightr   r8   r9   r9   r:   r     s    


zRectangle.__init__c             C   s   t j S )z%Return the vertices of the rectangle.)r   unit_rectangle)r2   r9   r9   r:   r<     s    zRectangle.get_pathc             C   sX   | j  \}}}}tjj||||}tj }|j||| j tj|| _|  j|7  _dS )a!  
        Notes
        -----
        This cannot be called until after this has been added to an Axes,
        otherwise unit conversion will fail. This makes it very important to
        call the accessor method and not directly access the transformation
        member variable.
        N)	_convert_unitsr	   Bboxfrom_extentsr   Zrotate_deg_aroundr   BboxTransformTor   )r2   x0y0x1y1bboxZ	rot_transr9   r9   r:   _update_patch_transform  s    	z!Rectangle._update_patch_transformc             C   s   | j | j | _d S )N)r   r   r   )r2   r9   r9   r:   
_update_x1	  s    zRectangle._update_x1c             C   s   | j | j | _d S )N)r   r   r   )r2   r9   r9   r:   
_update_y1  s    zRectangle._update_y1c             C   s<   | j | j}| j| j}| j | j}| j| j}||||fS )z Convert bounds of the rectangle.)r   r   r   r   r   r   )r2   r   r   r   r   r9   r9   r:   r     s
    zRectangle._convert_unitsc             C   s   | j   | jS )N)r   r   )r2   r9   r9   r:   re     s    zRectangle.get_patch_transformc             C   s   | j S )z,Return the left coordinate of the rectangle.)r   )r2   r9   r9   r:   get_x  s    zRectangle.get_xc             C   s   | j S )z.Return the bottom coordinate of the rectangle.)r   )r2   r9   r9   r:   get_y  s    zRectangle.get_yc             C   s   | j | jfS )z>Return the left and bottom coords of the rectangle as a tuple.)r   r   )r2   r9   r9   r:   get_xy#  s    zRectangle.get_xyc             C   s   | j S )z"Return the width of the rectangle.)r   )r2   r9   r9   r:   	get_width'  s    zRectangle.get_widthc             C   s   | j S )z#Return the height of the rectangle.)r   )r2   r9   r9   r:   
get_height+  s    zRectangle.get_heightc             C   s   || _ | j  d| _dS )z)Set the left coordinate of the rectangle.TN)r   r   rl   )r2   rH   r9   r9   r:   set_x/  s    zRectangle.set_xc             C   s   || _ | j  d| _dS )z+Set the bottom coordinate of the rectangle.TN)r   r   rl   )r2   rI   r9   r9   r:   set_y5  s    zRectangle.set_yc             C   s&   |\| _ | _| j  | j  d| _dS )z
        Set the left and bottom coordinates of the rectangle.

        Parameters
        ----------
        xy : (float, float)
        TN)r   r   r   r   rl   )r2   r   r9   r9   r:   set_xy;  s    zRectangle.set_xyc             C   s   || _ | j  d| _dS )zSet the width of the rectangle.TN)r   r   rl   )r2   r}   r9   r9   r:   	set_widthH  s    zRectangle.set_widthc             C   s   || _ | j  d| _dS )z Set the height of the rectangle.TN)r   r   rl   )r2   hr9   r9   r:   
set_heightN  s    zRectangle.set_heightc             G   s\   t |dkr|d \}}}}n|\}}}}|| _|| _|| _|| _| j  | j  d| _dS )a@  
        Set the bounds of the rectangle as *left*, *bottom*, *width*, *height*.

        The values may be passed as separate parameters or as a tuple::

            set_bounds(left, bottom, width, height)
            set_bounds((left, bottom, width, height))

        .. ACCEPTS: (left, bottom, width, height)
        r   r   TN)r0   r   r   r   r   r   r   rl   )r2   argslr   r}   r   r9   r9   r:   
set_boundsT  s    zRectangle.set_boundsc             C   s"   | j  \}}}}tjj||||S )zReturn the `.Bbox`.)r   r	   r   r   )r2   r   r   r   r   r9   r9   r:   get_bboxk  s    zRectangle.get_bboxN)r   )r   r   r   r   r   r   r   r   r<   r   r   r   r   re   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r9   r9   r9   r:   r     s.   "c               @   s   e Zd ZdZdd ZejdddZdd	 Ze	d
d Z
e
jdd Z
e	dd Zejdd Ze	dd Zejdd Ze	dd Zejdd Zdd Zdd ZdS )r   zA regular polygon patch.c             C   s(   d}|| j d | j d | j| j| jf S )Nz7RegularPolygon((%g, %g), %d, radius=%g, orientation=%g)r   r   )_xy_numVerticesrE   _orientation)r2   r   r9   r9   r:   r   v  s    zRegularPolygon.__str__   r   c             K   sH   || _ || _|| _|| _tj|| _tj | _	| j
  tj| f| dS )a  
        Parameters
        ----------
        xy : (float, float)
            The center position.

        numVertices : int
            The number of vertices.

        radius : float
            The distance from the center to each of the vertices.

        orientation : float
            The polygon rotation angle (in radians).

        **kwargs
            `Patch` properties:

            %(Patch)s
        N)r   r   r   rE   r   Zunit_regular_polygon_pathr	   r   _poly_transformr   r   r   )r2   r   numVerticesrD   orientationr8   r9   r9   r:   r   {  s    
zRegularPolygon.__init__c             C   s&   | j j j| jj| jj| j  d S )N)r   r   scalerD   rotater   r   r   )r2   r9   r9   r:   r     s    
z RegularPolygon._update_transformc             C   s   | j S )N)r   )r2   r9   r9   r:   r     s    zRegularPolygon.xyc             C   s   || _ | j  d S )N)r   r   )r2   r   r9   r9   r:   r     s    c             C   s   | j S )N)r   )r2   r9   r9   r:   r     s    zRegularPolygon.orientationc             C   s   || _ | j  d S )N)r   r   )r2   r   r9   r9   r:   r     s    c             C   s   | j S )N)rE   )r2   r9   r9   r:   rD     s    zRegularPolygon.radiusc             C   s   || _ | j  d S )N)rE   r   )r2   rD   r9   r9   r:   rD     s    c             C   s   | j S )N)r   )r2   r9   r9   r:   numvertices  s    zRegularPolygon.numverticesc             C   s
   || _ d S )N)r   )r2   r   r9   r9   r:   r     s    c             C   s   | j S )N)r   )r2   r9   r9   r:   r<     s    zRegularPolygon.get_pathc             C   s   | j   | jS )N)r   r   )r2   r9   r9   r:   re     s    z"RegularPolygon.get_patch_transformN)r   r   )r   r   r   r   r   r   r   r   r   r   r   setterr   rD   r   r<   re   r9   r9   r9   r:   r   s  s    c               @   s:   e Zd ZdZdZdd Zejdd Zdd Z	d	d
 Z
dS )	PathPatchzA general polycurve path patch.Tc             C   s&   d}|t | jjft| jjd  S )NzPathPatch%d((%g, %g) ...)r   )r0   r   rO   tuple)r2   r   r9   r9   r:   r     s    zPathPatch.__str__c             K   s   t j| f| || _dS )zl
        *path* is a `~.path.Path` object.

        Valid keyword arguments are:

        %(Patch)s
        N)r   r   r   )r2   r>   r8   r9   r9   r:   r     s    	zPathPatch.__init__c             C   s   | j S )N)r   )r2   r9   r9   r:   r<     s    zPathPatch.get_pathc             C   s
   || _ d S )N)r   )r2   r>   r9   r9   r:   set_path  s    zPathPatch.set_pathN)r   r   r   r   rn   r   r   r   r   r<   r   r9   r9   r9   r:   r     s   r   c               @   s^   e Zd ZdZdd ZejdddZdd Zd	d
 Z	dd Z
dd Zdd ZeeeddZdS )r   zA general polygon patch.c             C   s&   d}|t | jjft| jjd  S )NzPolygon%d((%g, %g) ...)r   )r0   r   rO   r   )r2   r   r9   r9   r:   r     s    zPolygon.__str__Tc             K   s"   t j| f| || _| j| dS )z
        *xy* is a numpy array with shape Nx2.

        If *closed* is *True*, the polygon will be closed so the
        starting and ending points are the same.

        Valid keyword arguments are:

        %(Patch)s
        N)r   r   _closedr   )r2   r   closedr8   r9   r9   r:   r     s    zPolygon.__init__c             C   s   | j S )zGet the `.Path` of the polygon.)r   )r2   r9   r9   r:   r<      s    zPolygon.get_pathc             C   s   | j S )z%Return whether the polygon is closed.)r   )r2   r9   r9   r:   
get_closed  s    zPolygon.get_closedc             C   s4   | j t|krdS t|| _ | j| j  d| _dS )z
        Set whether the polygon is closed.

        Parameters
        ----------
        closed : bool
           True if the polygon is closed
        NT)r   r   r   r   rl   )r2   r   r9   r9   r:   
set_closed  s
    	
zPolygon.set_closedc             C   s   | j jS )z
        Get the vertices of the path.

        Returns
        -------
        (N, 2) numpy array
            The coordinates of the vertices.
        )r   rO   )r2   r9   r9   r:   r     s    	zPolygon.get_xyc             C   s   t j|}|j\}}| jrT|dks>|dkr||d |d kj r|t j||d gg}n(|dkr||d |d kj r||dd	 }t|| jd| _d| _	dS )
a  
        Set the vertices of the polygon.

        Parameters
        ----------
        xy : (N, 2) array-like
            The coordinates of the vertices.

        Notes
        -----
        Unlike `~.path.Path`, we do not ignore the last input vertex. If the
        polygon is meant to be closed, and the last point of the polygon is not
        equal to the first, we assume that the user has not explicitly passed a
        ``CLOSEPOLY`` vertex, and add it ourselves.
        r   r      N)r   Tr  r  )
rP   r   shaper   rU   concatenateallr   r   rl   )r2   r   Znverts_r9   r9   r:   r   "  s    

$zPolygon.set_xyz/The vertices of the path as (N, 2) numpy array.)docN)T)r   r   r   r   r   r   r   r   r<   r  r  r   r   r   r   r9   r9   r9   r:   r     s   !c               @   s`   e Zd ZdZdd ZejdddZdd Zd	d
 Z	dd Z
dd Zdd Zdd Zdd ZdS )r   zWedge shaped patch.c             C   s0   | j d | j d | j| j| j| jf}d}|| S )Nr   r   z<Wedge(center=(%g, %g), r=%g, theta1=%g, theta2=%g, width=%s))centerrtheta1theta2r   )r2   r   r   r9   r9   r:   r   J  s    zWedge.__str__Nc             K   sF   t j| f| || _|| | _| _|| | _| _tj | _	| j
  dS )a.  
        A wedge centered at *x*, *y* center with radius *r* that
        sweeps *theta1* to *theta2* (in degrees).  If *width* is given,
        then a partial wedge is drawn from inner radius *r* - *width*
        to outer radius *r*.

        Valid keyword arguments are:

        %(Patch)s
        N)r   r   r
  r  r   r  r  r	   rf   _patch_transform_recompute_path)r2   r
  r  r  r  r   r8   r9   r9   r:   r   P  s    
zWedge.__init__c       	      C   s&  t | j| j d dkr(d\}}tj}n| j| j }}tj}tj||}| jd k	r|j}|jd d d | j	| j  | j	 }t
j|||dd d f dg}t
j|j|j|tjg}||t|j< n<t
j|jd|jdd d f d	gg}t
j|j||tjgg}|| j	9 }|t
j| j7 }t||| _d S )
Nh  g-q=r   r   )r   r  r  )r   r   )r   r   )r   r   )absr  r  r   rR   LINETOarcr   rO   r  rP   ZvstackZhstackrN   	CLOSEPOLYr0   r   r
  r   )	r2   r  r  Z	connectorr  Zv1Zv2vrt   r9   r9   r:   r  c  s"    
"$
zWedge._recompute_pathc             C   s   d | _ || _d| _d S )NT)r   r
  rl   )r2   r
  r9   r9   r:   
set_center  s    zWedge.set_centerc             C   s   d | _ || _d| _d S )NT)r   r  rl   )r2   rD   r9   r9   r:   
set_radius  s    zWedge.set_radiusc             C   s   d | _ || _d| _d S )NT)r   r  rl   )r2   r  r9   r9   r:   
set_theta1  s    zWedge.set_theta1c             C   s   d | _ || _d| _d S )NT)r   r  rl   )r2   r  r9   r9   r:   
set_theta2  s    zWedge.set_theta2c             C   s   d | _ || _d| _d S )NT)r   r   rl   )r2   r   r9   r9   r:   r     s    zWedge.set_widthc             C   s   | j d kr| j  | j S )N)r   r  )r2   r9   r9   r:   r<     s    
zWedge.get_path)N)r   r   r   r   r   r   r   r   r  r  r  r  r  r   r<   r9   r9   r9   r:   r   G  s   c            
       s|   e Zd ZdZdd Zeddgddgddgddgddgddgddgddggd	d
Zejd fdd	Z	dd Z
dd Z  ZS )r   zAn arrow patch.c             C   s   dS )NzArrow()r9   )r2   r9   r9   r:   r     s    zArrow.__str__g        g?g?g333333?      ?T)r   c                sF   t  jf | tj jtj|||jtj||j	||j
 | _dS )aK  
        Draws an arrow from (*x*, *y*) to (*x* + *dx*, *y* + *dy*).
        The width of the arrow is scaled by *width*.

        Parameters
        ----------
        x : float
            x coordinate of the arrow tail.
        y : float
            y coordinate of the arrow tail.
        dx : float
            Arrow length in the x direction.
        dy : float
            Arrow length in the y direction.
        width : float, default: 1
            Scale factor for the width of the arrow. With a default value of 1,
            the tail width is 0.2 and head width is 0.6.
        **kwargs
            Keyword arguments control the `Patch` properties:

            %(Patch)s

        See Also
        --------
        FancyArrow
            Patch that allows independent control of the head and tail
            properties.
        N)ru   r   r	   r   r   rP   hypotr   arctan2r   frozenr  )r2   rH   rI   dxdyr   r8   )rw   r9   r:   r     s
    zArrow.__init__c             C   s   | j S )N)r   )r2   r9   r9   r:   r<     s    zArrow.get_pathc             C   s   | j S )N)r  )r2   r9   r9   r:   re     s    zArrow.get_patch_transformggg333333ӿ)r  )r   r   r   r   r   r   r   r   r   r   r<   re   r   r9   r9   )rw   r:   r     s   %c                   s4   e Zd ZdZdZdd Zejd fd
d	Z  Z	S )r   zP
    Like Arrow, but lets you set head width and head height independently.
    Tc             C   s   dS )NzFancyArrow()r9   )r2   r9   r9   r:   r     s    zFancyArrow.__str__MbP?FNfullr   c                s  |dkrd| }|dkr d| }t j||}|r6|}n|| }|sTt jddg}n6|||
|f\}}}}t jddg| | d g| d|  | d g| | d g| dgg}|s||dg7 }|r||d dg7 }|	dkr|}nT|ddg }|	d	kr |}n8|	d
kr,t j|dd |ddd g}ntd|	 |dkrT|| }|| }nd\}}||g| |gg}t j|||| || f }t j|fddi| dS )a  
        Parameters
        ----------
        width: float, default: 0.001
            Width of full arrow tail.

        length_includes_head: bool, default: False
            True if head is to be counted in calculating the length.

        head_width: float or None, default: 3*width
            Total width of the full arrow head.

        head_length: float or None, default: 1.5*head_width
            Length of arrow head.

        shape: ['full', 'left', 'right'], default: 'full'
            Draw the left-half, right-half, or full arrow.

        overhang: float, default: 0
            Fraction that the arrow is swept back (0 overhang means
            triangular shape). Can be negative or greater than one.

        head_starts_at_zero: bool, default: False
            If True, the head starts being drawn at coordinate 0
            instead of ending at coordinate 0.

        **kwargs
            `.Patch` properties:

            %(Patch)s
        Nr@   g      ?r   r  g        r   leftrightr!  zGot unknown shape: %sr   Tr  r  r  )r   r   )	rP   r  emptyarrayr  
ValueErrordotru   r   )r2   rH   rI   r  r  r   Zlength_includes_head
head_widthhead_lengthr  ZoverhangZhead_starts_at_zeror8   ZdistancelengthZvertsZhwZhlZhsr   Zleft_half_arrowZcoordsZright_half_arrowcxZsxM)rw   r9   r:   r     sJ    #



zFancyArrow.__init__)r   FNNr!  r   F)
r   r   r   r   rn   r   r   r   r   r   r9   r9   )rw   r:   r     s     
r  )r   c               @   s(   e Zd ZdZdd Zejd	ddZdS )
r   z*A polygon-approximation of a circle patch.c             C   s$   d}|| j d | j d | j| jf S )Nz1CirclePolygon((%g, %g), radius=%g, resolution=%d)r   r   )r   rE   r   )r2   r   r9   r9   r:   r   F  s    zCirclePolygon.__str__r      c             K   s    t j| |||fddi| dS )a  
        Create a circle at *xy* = (*x*, *y*) with given *radius*.

        This circle is approximated by a regular polygon with *resolution*
        sides.  For a smoother circle drawn with splines, see `Circle`.

        Valid keyword arguments are:

        %(Patch)s
        r   r   N)r   r   )r2   r   rD   
resolutionr8   r9   r9   r:   r   J  s
    zCirclePolygon.__init__N)r   r/  )r   r   r   r   r   r   r   r   r9   r9   r9   r:   r   C  s
    c               @   s   e Zd ZdZdd ZejdddZdd Zd	d
 Z	dd Z
dd Zdd ZeeeZdd Zdd ZeeeZdd Zdd ZeeeZdd Zdd ZeeeZdS )r   zA scale-free ellipse.c             C   s,   | j d | j d | j| j| jf}d}|| S )Nr   r   z3Ellipse(xy=(%s, %s), width=%s, height=%s, angle=%s))_centerr   r   r   )r2   r   r   r9   r9   r:   r   b  s    zEllipse.__str__r   c             K   s@   t j| f| || _|| | _| _|| _tj | _t	j
 | _dS )a  
        Parameters
        ----------
        xy : (float, float)
            xy coordinates of ellipse centre.
        width : float
            Total length (diameter) of horizontal axis.
        height : float
            Total length (diameter) of vertical axis.
        angle : float, default: 0
            Rotation in degrees anti-clockwise.

        Notes
        -----
        Valid keyword arguments are:

        %(Patch)s
        N)r   r   r1  r   r   _angler   Zunit_circler   r	   rf   r  )r2   r   r   r   r   r8   r9   r9   r:   r   h  s    
zEllipse.__init__c             C   sd   | j | jd | j| jd f}| j | j}| j| j}tj j|d |d j| j	j
| | _dS )a!  
        Notes
        -----
        This cannot be called until after this has been added to an Axes,
        otherwise unit conversion will fail. This makes it very important to
        call the accessor method and not directly access the transformation
        member variable.
        r   r   g      ?N)r   r1  r   r   r   r	   r   r   Z
rotate_degr   r   r  )r2   r
  r   r   r9   r9   r:   _recompute_transform  s    	zEllipse._recompute_transformc             C   s   | j S )zReturn the path of the ellipse.)r   )r2   r9   r9   r:   r<     s    zEllipse.get_pathc             C   s   | j   | jS )N)r3  r  )r2   r9   r9   r:   re     s    zEllipse.get_patch_transformc             C   s   || _ d| _dS )zs
        Set the center of the ellipse.

        Parameters
        ----------
        xy : (float, float)
        TN)r1  rl   )r2   r   r9   r9   r:   r    s    zEllipse.set_centerc             C   s   | j S )z!Return the center of the ellipse.)r1  )r2   r9   r9   r:   
get_center  s    zEllipse.get_centerc             C   s   || _ d| _dS )zl
        Set the width of the ellipse.

        Parameters
        ----------
        width : float
        TN)r   rl   )r2   r   r9   r9   r:   r     s    zEllipse.set_widthc             C   s   | j S )z2
        Return the width of the ellipse.
        )r   )r2   r9   r9   r:   r     s    zEllipse.get_widthc             C   s   || _ d| _dS )zn
        Set the height of the ellipse.

        Parameters
        ----------
        height : float
        TN)r   rl   )r2   r   r9   r9   r:   r     s    zEllipse.set_heightc             C   s   | j S )z!Return the height of the ellipse.)r   )r2   r9   r9   r:   r     s    zEllipse.get_heightc             C   s   || _ d| _dS )zl
        Set the angle of the ellipse.

        Parameters
        ----------
        angle : float
        TN)r2  rl   )r2   r   r9   r9   r:   	set_angle  s    zEllipse.set_anglec             C   s   | j S )z Return the angle of the ellipse.)r2  )r2   r9   r9   r:   	get_angle  s    zEllipse.get_angleN)r   )r   r   r   r   r   r   r   r   r3  r<   re   r  r4  r   r
  r   r   r   r   r   r   r5  r6  r   r9   r9   r9   r:   r   _  s&   


c               @   sB   e Zd ZdZdd ZejdddZdd Zd	d
 Z	e
e	eZdS )r   zA circle patch.c             C   s$   | j d | j d | jf}d}|| S )Nr   r   zCircle(xy=(%g, %g), radius=%g))r
  rD   )r2   r   r   r9   r9   r:   r     s    zCircle.__str__r   c             K   s&   t j| ||d |d f| || _dS )a   
        Create a true circle at center *xy* = (*x*, *y*) with given *radius*.

        Unlike `CirclePolygon` which is a polygonal approximation, this uses
        Bezier splines and is much closer to a scale-free circle.

        Valid keyword arguments are:

        %(Patch)s
        r  N)r   r   rD   )r2   r   rD   r8   r9   r9   r:   r     s    zCircle.__init__c             C   s   d|  | _ | _d| _dS )zm
        Set the radius of the circle.

        Parameters
        ----------
        radius : float
        r  TN)r   r   rl   )r2   rD   r9   r9   r:   r    s    zCircle.set_radiusc             C   s
   | j d S )z Return the radius of the circle.g       @)r   )r2   r9   r9   r:   
get_radius  s    zCircle.get_radiusN)r   )r   r   r   r   r   r   r   r   r  r7  r   rD   r9   r9   r9   r:   r     s   c               @   s6   e Zd ZdZdd ZejdddZej	dd	 Z
d
S )r   a  
    An elliptical arc, i.e. a segment of an ellipse.

    Due to internal optimizations, there are certain restrictions on using Arc:

    - The arc cannot be filled.

    - The arc must be used in an `~.axes.Axes` instance. It can not be added
      directly to a `.Figure` because it is optimized to only render the
      segments that are inside the axes bounding box with high resolution.
    c             C   s4   | j d | j d | j| j| j| j| jf}d}|| S )Nr   r   zEArc(xy=(%g, %g), width=%g, height=%g, angle=%g, theta1=%g, theta2=%g))r
  r   r   r   r  r  )r2   r   r   r9   r9   r:   r     s    zArc.__str__             v@c       	      K   s>   |j dd}|rtdtj| ||||f| || _|| _dS )a  
        Parameters
        ----------
        xy : (float, float)
            The center of the ellipse.

        width : float
            The length of the horizontal axis.

        height : float
            The length of the vertical axis.

        angle : float
            Rotation of the ellipse in degrees (counterclockwise).

        theta1, theta2 : float, default: 0, 360
            Starting and ending angles of the arc in degrees. These values
            are relative to *angle*, e.g. if *angle* = 45 and *theta1* = 90
            the absolute starting angle is 135.
            Default *theta1* = 0, *theta2* = 360, i.e. a complete ellipse.
            The arc is drawn in the counterclockwise direction.
            Angles greater than or equal to 360, or smaller than 0, are
            represented by an equivalent angle in the range [0, 360), by
            taking the input value mod 360.

        Other Parameters
        ----------------
        **kwargs : `.Patch` properties
            Most `.Patch` properties are supported as keyword arguments,
            with the exception of *fill* and *facecolor* because filling is
            not supported.

        %(Patch)s
        r5   FzArc objects can not be filledN)
setdefaultr'  r   r   r  r  )	r2   r   r   r   r   r  r  r8   r5   r9   r9   r:   r   "  s    %zArc.__init__c                s&  t | dstd| j sdS | j  | j| j}| j| j}dd }| j}| j	}||kr||kop|d |d k r|| j|| }|| j	|| }| j
 }|j||f|jd \}}	d}
||
k r|	|
k rtj||| _tj| |S dd   fdd}tj| jj| j j  }tj j|}t }xvt|jdd |jdd D ]T\}}||| }|j\}}tjtj||d d }|j |||k ||k @   qHW t!||g }|}tj"|}|j#tj$|tj%|f}| j}x>|D ]6}|rtj||d| _tj| | d}nd}|}qW || _dS )a  
        Draw the arc to the given *renderer*.

        Notes
        -----
        Ellipses are normally drawn using an approximation that uses
        eight cubic Bezier splines.  The error of this approximation
        is 1.89818e-6, according to this unverified source:

          Lancaster, Don.  *Approximating a Circle or an Ellipse Using
          Four Bezier Cubic Splines.*

          https://www.tinaja.com/glib/ellipse4.pdf

        There is a use case where very large ellipses must be drawn
        with very high accuracy, and it is too expensive to render the
        entire ellipse with enough segments (either splines or line
        segments).  Therefore, in the case where either radius of the
        ellipse is large enough that the error of the spline
        approximation will be visible (greater than one pixel offset
        from the ideal), a different technique is used.

        In that case, only the visible parts of the ellipse are drawn,
        with each visible arc using a fixed number of spline segments
        (8).  The algorithm proceeds as follows:

        1. The points where the ellipse intersects the axes bounding
           box are located.  (This is done be performing an inverse
           transformation on the axes bbox such that it is relative
           to the unit circle -- this makes the intersection
           calculation much easier than doing rotated ellipse
           intersection directly).

           This uses the "line intersecting a circle" algorithm from:

               Vince, John.  *Geometry for Computer Graphics: Formulae,
               Examples & Proofs.*  London: Springer-Verlag, 2005.

        2. The angles of each of the intersection points are calculated.

        3. Proceeding counterclockwise starting in the positive
           x-direction, each of the visible arc-segments between the
           pairs of vertices are drawn using the Bezier arc
           approximation technique implemented in `.Path.arc`.
        axesz'Arcs can only be used in Axes instancesNc             S   s@   t j| } t j| }t j| }t jt j|| |}|d d S )Nih  )rP   deg2radcossinrad2degr  )thetar   rH   rI   Zsthetar9   r9   r:   theta_stretch  s
    


zArc.draw.<locals>.theta_stretchih  r   g      ?gJؿ>g      ?c             S   s   ||  }|| }|| ||  }| | ||  }|| }|| }	|	dkrt jd|}
t j|	}t j|| |
| |  | | | t||  | g|| |
| |  | | | t||  | ggS t jdS d S )Ng        r   r   r  )r   r  )rP   copysignsqrtr&  r  r%  )r   r   r   r   r  r  Zdr2DZD2ZdiscrimZsign_dyZsqrt_discrimr9   r9   r:   line_circle_intersect  s    
 z'Arc.draw.<locals>.line_circle_intersectc                s   d}|| k r||  }}n
| | }}||k r6|| }}n
|| }} | |||}	|	j \}
}|	|| |
k |
|| k @ || |k @ ||| k @  S )Ng&.>)T)r   r   r   r   epsilonZx0eZx1eZy0eZy1eZxysxsZys)rE  r9   r:   segment_circle_intersect  s    


z*Arc.draw.<locals>.segment_circle_intersectr      FT)r   r   g\! Ag\!Ar  )&hasattrRuntimeErrorr   r3  r   r   r   r   r  r  rb   r   r   r  r   r   r   r	   r   r;  r   r;   invertedr   ZtransformedsetziprO   rF  rP   r?  r  r1   sortedr<  rG   r=  r>  )r2   r   r   r   rA  r  r  Zdata_to_screen_transZpwidthZpheightZ	inv_errorrI  Zbox_path_transformZbox_pathZthetasZp0p1r   rH   rI   r@  Z
last_thetaZ
theta1_radrV   Zpath_originalr9   )rE  r:   r   P  s\    /
	(
 


zArc.drawN)r8  r8  r9  )r   r   r   r   r   r   r   r   r   r   r   r9   r9   r9   r:   r     s    ,Tc             C   s   |dkri }|j  }|jdd}|j|}| j|}t|j|d  |j|d  f|j| |j| |t	j
 dd}|j| |j| dS )a>  
    A debug function to draw a rectangle around the bounding
    box returned by an artist's `.Artist.get_window_extent`
    to test whether the artist is returning the correct bbox.

    *props* is a dict of rectangle props with the additional property
    'pad' that sets the padding around the bbox in points.
    Npad   r  F)r   r   r   r5   r   clip_on)copypopr   r   r   r   r   r   r   r	   rf   r1   r   )r   r   r   r5   rR  r   r  r9   r9   r:   bbox_artist  s    	


rW  kc             C   s@   t | j| jf| j| j|ddd}|dk	r2|j| |j| dS )z
    A debug function to draw a rectangle around the bounding
    box returned by an artist's `.Artist.get_window_extent`
    to test whether the artist is returning the correct bbox.
    F)r   r   r   r   r5   rT  N)r   r   r   r   r   ra   r   )r   r   r3   r=   r  r9   r9   r:   	draw_bbox  s
    
rY  c             C   s   dj djtdj t| S )z
    A helper function for the _Style class.  Given the dictionary of
    {stylename: styleclass}, return a string rep of the list of keys.
    Used to update the documentation.
    z[{}]|z '{}' )formatjoinrS   rP  )Z_stylesr9   r9   r:   _simpleprint_styles   s    r]  c               @   s<   e Zd ZdZdd Zedd Zedd Zedd	 Zd
S )_Stylez
    A base class for the Styles. It is meant to be a container class,
    where actual styles are declared as subclass of it, and it
    provides some helper functions.
    c       	      K   s   |j ddjd}|d j }y| j| }W n0 tk
r\ } ztd| |W Y dd}~X nX y(dd |d	d D }d
d |D }W n0 tk
r } ztd| |W Y dd}~X nX |j| |f |S )z>Return the instance of the subclass with the given style name.  ,r   zUnknown style : %sNc             S   s   g | ]}|j d qS )=)rT   )rJ   csr9   r9   r:   
<listcomp>=  s    z"_Style.__new__.<locals>.<listcomp>r   c             S   s   i | ]\}}t ||qS r9   )rx   )rJ   rX  r  r9   r9   r:   
<dictcomp>>  s    z"_Style.__new__.<locals>.<dictcomp>zIncorrect style argument : %s)replacerT   lower_style_listKeyErrorr'  r1   )	clsZ	stylenamekwZ_list_name_clserrZ
_args_pair_argsr9   r9   r:   __new__/  s     
z_Style.__new__c             C   s   | j S )z(Return a dictionary of available styles.)rh  )rj  r9   r9   r:   
get_stylesF  s    z_Style.get_stylesc                s   ddd t | jj D }dd t| D  djdd	  D }d
jd|djdd	 t|d  D |f fdd|dd D |df}tj|ddS )z5Return the available styles as pretty-printed string.ClassNameAttrsc             S   s:   g | ]2\}}|j d | d ttj|dd p2dfqS )z``r   Noner  )r   r   inspect	signature)rJ   namerj  r9   r9   r:   rd  O  s   z(_Style.pprint_styles.<locals>.<listcomp>c             S   s   g | ]}t d d |D qS )c             s   s   | ]}t |V  qd S )N)r0   )rJ   cellr9   r9   r:   rM   V  s    z2_Style.pprint_styles.<locals>.<listcomp>.<genexpr>)max)rJ   columnr9   r9   r:   rd  V  s    z  c             s   s   | ]}d | V  qdS )rb  Nr9   )rJ   clr9   r9   r:   rM   W  s    z'_Style.pprint_styles.<locals>.<genexpr>r.  r`  c             s   s   | ]\}}|j |V  qd S )N)ljust)rJ   ry  r|  r9   r9   r:   rM   [  s    r   c                s&   g | ]}d j dd t| D qS )z  c             s   s   | ]\}}|j |V  qd S )N)r}  )rJ   ry  r|  r9   r9   r:   rM   ]  s    z2_Style.pprint_styles.<locals>.<listcomp>.<genexpr>)r\  rO  )rJ   row)col_lenr9   r:   rd  ]  s   r   Nr_  r  )prefixrr  rs  rt  )r  z  )rP  rh  itemsrO  r\  textwrapindent)rj  tableZtable_formatstrZ	rst_tabler9   )r  r:   pprint_stylesK  s    

z_Style.pprint_stylesc             C   s,   t || jstd|| jf || j|< dS )zRegister a new style.z%s must be a subclass of %sN)
issubclass_Baser'  rh  )rj  rx  styler9   r9   r:   registerd  s    z_Style.registerN)	r   r   r   r   rp  classmethodrq  r  r  r9   r9   r9   r:   r^  )  s
   r^  )rx  c            C   s.   |dkrt jt| |dS || |p(|jj < |S )z=Class decorator that stashes a class in a (style) dictionary.N)rx  )r   r   _register_styler   rg  )Z
style_listrj  rx  r9   r9   r:   r  m  s    r  c               @   s   e Zd ZdZi ZG dd dZeeG dd deZeeG dd deZeeG dd	 d	eZ	eeG d
d de	Z
eeG dd deZeeG dd deZeeG dd deZeeG dd deZeeG dd deZdS )BoxStyleat  
    `BoxStyle` is a container class which defines several
    boxstyle classes, which are used for `FancyBboxPatch`.

    A style object can be created as::

           BoxStyle.Round(pad=0.2)

    or::

           BoxStyle("Round", pad=0.2)

    or::

           BoxStyle("Round, pad=0.2")

    The following boxstyle classes are defined.

    %(AvailableBoxstyles)s

    An instance of any boxstyle class is an callable object,
    whose call signature is::

       __call__(self, x0, y0, width, height, mutation_size, aspect_ratio=1.)

    and returns a `.Path` instance. *x0*, *y0*, *width* and
    *height* specify the location and size of the box to be
    drawn. *mutation_scale* determines the overall size of the
    mutation (by which I mean the transformation of the rectangle to
    the fancy box).  *mutation_aspect* determines the aspect-ratio of
    the mutation.
    c               @   s"   e Zd ZdZdd ZdddZdS )	zBoxStyle._Basea  
        Abstract base class for styling of `.FancyBboxPatch`.

        This class is not an artist itself.  The `__call__` method returns the
        `~matplotlib.path.Path` for outlining the fancy box. The actual drawing
        is handled in `.FancyBboxPatch`.

        Subclasses may only use parameters with default values in their
        ``__init__`` method because they must be able to be initialized
        without arguments.

        Subclasses must implement the `transmute` method. It receives the
        enclosing rectangle *x0, y0, width, height* as well as the
        *mutation_size*, which scales the outline properties such as padding.
        It returns the outline of the fancy box as `.path.Path`.
        c             C   s   t ddS )z7Return the `~.path.Path` outlining the given rectangle.zDerived must overrideN)r   )r2   r   r   r   r   mutation_sizer9   r9   r:   	transmute  s    zBoxStyle._Base.transmute      ?c       
      C   sz   |dk	rd|| ||  }}| j |||||}|j|j }}	|dddf | |dddf< t||	S | j |||||S dS )a  
            Given the location and size of the box, return the path of
            the box around it.

            Parameters
            ----------
            x0, y0, width, height : float
                Location and size of the box.
            mutation_size : float
                A reference scale for the mutation.
            aspect_ratio : float, default: 1
                Aspect-ratio for the mutation.

            Returns
            -------
            `~matplotlib.path.Path`
            Nr   )r  rO   rN   r   )
r2   r   r   r   r   r  aspect_ratior>   rO   rN   r9   r9   r:   __call__  s     
zBoxStyle._Base.__call__N)r  )r   r   r   r   r  r  r9   r9   r9   r:   r    s   r  c                   s*   e Zd ZdZd fdd	Zdd Z  ZS )zBoxStyle.Squarez
        A square box.

        Parameters
        ----------
        pad : float, default: 0.3
            The amount of padding around the original box.
        333333?c                s   || _ t j  d S )N)rR  ru   r   )r2   rR  )rw   r9   r:   r     s    zBoxStyle.Square.__init__c       	      C   sr   || j  }|d|  |d|   }}|| ||  }}|| ||  }}t||f||f||f||f||fgddS )Nr  T)r   )rR  r   )	r2   r   r   r   r   r  rR  r   r   r9   r9   r:   r    s    
"zBoxStyle.Square.transmute)r  )r   r   r   r   r   r  r   r9   r9   )rw   r:   Square  s   	r  c                   s*   e Zd ZdZd fdd	Zdd Z  ZS )zBoxStyle.Circlez
        A circular box.

        Parameters
        ----------
        pad : float, default: 0.3
            The amount of padding around the original box.
        333333?c                s   || _ t j  d S )N)rR  ru   r   )r2   rR  )rw   r9   r:   r     s    zBoxStyle.Circle.__init__c             C   s`   || j  }|d|  |d|   }}|| ||  }}tj||d  ||d  ft||d S )Nr  )rR  r   Zcirclerz  )r2   r   r   r   r   r  rR  r9   r9   r:   r    s
    
zBoxStyle.Circle.transmute)r  )r   r   r   r   r   r  r   r9   r9   )rw   r:   r     s   	r   c                   s*   e Zd ZdZd fdd	Zdd Z  ZS )zBoxStyle.LArrowz
        A box in the shape of a left-pointing arrow.

        Parameters
        ----------
        pad : float, default: 0.3
            The amount of padding around the original box.
        333333?c                s   || _ t j  d S )N)rR  ru   r   )r2   rR  )rw   r9   r:   r   	  s    zBoxStyle.LArrow.__init__c             C   s   || j  }|d|  |d|   }}|| ||  }}|| ||  }}|| d }	|	d }
||d  }t||
 |f||f||f||
 |f||
 ||
 f||	 ||	 f||
 ||
 f||
 |f||
 |fg	ddS )Nr  gffffff?T)r   )rR  r   )r2   r   r   r   r   r  rR  r   r   r  dxxr9   r9   r:   r    s    
"zBoxStyle.LArrow.transmute)r  )r   r   r   r   r   r  r   r9   r9   )rw   r:   LArrow  s   	r  c                   s*   e Zd ZdZd fdd	Zdd Z  ZS )zBoxStyle.RArrowz
        A box in the shape of a right-pointing arrow.

        Parameters
        ----------
        pad : float, default: 0.3
            The amount of padding around the original box.
        333333?c                s   t  j| d S )N)ru   r   )r2   rR  )rw   r9   r:   r   *  s    zBoxStyle.RArrow.__init__c             C   sF   t jj| |||||}d| | |jd d df  |jd d df< |S )Nr  r   )r  r  r  rO   )r2   r   r   r   r   r  pr9   r9   r:   r  -  s    
,zBoxStyle.RArrow.transmute)r  )r   r   r   r   r   r  r   r9   r9   )rw   r:   RArrow   s   	r  c                   s*   e Zd ZdZd fdd	Zdd Z  ZS )zBoxStyle.DArrowz
        A box in the shape of a two-way arrow.

        Parameters
        ----------
        pad : float, default: 0.3
            The amount of padding around the original box.
        333333?c                s   || _ t j  d S )N)rR  ru   r   )r2   rR  )rw   r9   r:   r   @  s    zBoxStyle.DArrow.__init__c             C   s   || j  }|d|  }|| ||  }}|| ||  }}|| d }	|	d }
||d  }t||
 |f||f|||
 f||	 |
 ||	 f|||
 f||f||
 |f||
 ||
 f||	 ||	 f||
 ||
 f||
 |f||
 |fgddS )Nr  gffffff?T)r   )rR  r   )r2   r   r   r   r   r  rR  r   r   r  r  r9   r9   r:   r  D  s    

zBoxStyle.DArrow.transmute)r  )r   r   r   r   r   r  r   r9   r9   )rw   r:   DArrow3  s   	r  c                   s*   e Zd ZdZd fdd	Zdd Z  ZS )	zBoxStyle.Rounda   
        A box with round corners.

        Parameters
        ----------
        pad : float, default: 0.3
            The amount of padding around the original box.
        rounding_size : float, default: *pad*
            Radius of the corners.
        333333?Nc                s   || _ || _t j  d S )N)rR  rounding_sizeru   r   )r2   rR  r  )rw   r9   r:   r   g  s    zBoxStyle.Round.__init__c             C   s(  || j  }| jr|| j }n|}|d|  |d|   }}|| ||  }}|| ||  }}	|| |f|| |f||f||| f||	| f||	f|| |	f|| |	f||	f||	| f||| f||f|| |f|| |fg}
tjtjtjtjtjtjtjtjtjtjtjtjtjtjg}t|
|}|S )Nr  )rR  r  r   rR   r  CURVE3r  )r2   r   r   r   r   r  rR  drr   r   cpcomr>   r9   r9   r:   r  l  s:    






zBoxStyle.Round.transmute)r  N)r   r   r   r   r   r  r   r9   r9   )rw   r:   Round[  s   r  c                   s*   e Zd ZdZd fdd	Zdd Z  ZS )	zBoxStyle.Round4z
        A box with rounded edges.

        Parameters
        ----------
        pad : float, default: 0.3
            The amount of padding around the original box.
        rounding_size : float, default: *pad*/2
             Rounding of edges.
        333333?Nc                s   || _ || _t j  d S )N)rR  r  ru   r   )r2   rR  r  )rw   r9   r:   r     s    zBoxStyle.Round4.__init__c             C   sZ  || j  }| jr|| j }n|d }|d|  d|  }|d|  d|  }|| | || |  }}|| ||  }}	||f|| || f|| || f||f|| || f|| |	| f||	f|| |	| f|| |	| f||	f|| |	| f|| || f||f||fg}
tjtjtjtjtjtjtjtjtjtjtjtjtjtjg}t|
|}|S )Ng       @r  )rR  r  r   rR   ZCURVE4r  )r2   r   r   r   r   r  rR  r  r   r   r  r  r>   r9   r9   r:   r    s,    
""""

zBoxStyle.Round4.transmute)r  N)r   r   r   r   r   r  r   r9   r9   )rw   r:   Round4  s   r  c                   s2   e Zd ZdZd
 fdd	Zdd Zdd	 Z  ZS )zBoxStyle.Sawtootha  
        A box with a sawtooth outline.

        Parameters
        ----------
        pad : float, default: 0.3
            The amount of padding around the original box.
        tooth_size : float, default: *pad*/2
             Size of the sawtooth.
        333333?Nc                s   || _ || _t j  d S )N)rR  
tooth_sizeru   r   )r2   rR  r  )rw   r9   r:   r     s    zBoxStyle.Sawtooth.__init__c             C   sR  || j  }| jd kr$| j d | }n
| j| }|d }|d|  | }|d|  | }tt|| |d  d }	|| |	 }
tt|| |d  d }|| | }|| | || |  }}|| ||  }}|f|| |
d tj|	d   || f}|f|| ||| |g|	 || f}|f|| ||| |g|	 || f}|f|| |d tj|d   || f}|f|| |
d tj|	d   || f}|f|| ||| |g|	 || f}|f|| ||| |g| || f}|f|| |d tj|d   || f}t||t||t||t|||d |d ff}|S )Ng      ?r  r   )rR  r  introundrP   ZarangerO  )r2   r   r   r   r   r  rR  r  Ztooth_size2Zdsx_nZdsxZdsy_nZdsyr   r   Zbottom_saw_xZbottom_saw_yZright_saw_xZright_saw_yZ	top_saw_xZ	top_saw_yZ
left_saw_xZ
left_saw_ysaw_verticesr9   r9   r:   _get_sawtooth_vertices  sV    


z(BoxStyle.Sawtooth._get_sawtooth_verticesc             C   s"   | j |||||}t|dd}|S )NT)r   )r  r   )r2   r   r   r   r   r  r  r>   r9   r9   r:   r  '	  s    
zBoxStyle.Sawtooth.transmute)r  N)r   r   r   r   r   r  r  r   r9   r9   )rw   r:   Sawtooth  s   Jr  c                   s*   e Zd ZdZd fdd	Zdd Z  ZS )	zBoxStyle.Roundtootha  
        A box with a rounded sawtooth outline.

        Parameters
        ----------
        pad : float, default: 0.3
            The amount of padding around the original box.
        tooth_size : float, default: *pad*/2
             Size of the sawtooth.
        333333?Nc                s   t  j|| d S )N)ru   r   )r2   rR  r  )rw   r9   r:   r   9	  s    zBoxStyle.Roundtooth.__init__c             C   s\   | j |||||}tj||d gg}tjgtjtjgt|d d   tjg }t||S )Nr   r   r  )r  rP   r  r   rR   r  r0   r  )r2   r   r   r   r   r  r  rN   r9   r9   r:   r  <	  s    "
zBoxStyle.Roundtooth.transmute)r  N)r   r   r   r   r   r  r   r9   r9   )rw   r:   
Roundtooth-	  s   r  N)r   r   r   r   rh  r  r  r  r   r  r  r  r  r  r  r  r9   r9   r9   r:   r  u  s*    8 '<3`r  c               @   s   e Zd ZdZi ZG dd dZeeG dd deZeeG dd deZeeG dd	 d	eZ	eeG d
d deZ
eeG dd deZdS )ConnectionStylea  
    `ConnectionStyle` is a container class which defines
    several connectionstyle classes, which is used to create a path
    between two points.  These are mainly used with `FancyArrowPatch`.

    A connectionstyle object can be either created as::

           ConnectionStyle.Arc3(rad=0.2)

    or::

           ConnectionStyle("Arc3", rad=0.2)

    or::

           ConnectionStyle("Arc3, rad=0.2")

    The following classes are defined

    %(AvailableConnectorstyles)s

    An instance of any connection style class is an callable object,
    whose call signature is::

        __call__(self, posA, posB,
                 patchA=None, patchB=None,
                 shrinkA=2., shrinkB=2.)

    and it returns a `.Path` instance. *posA* and *posB* are
    tuples of (x, y) coordinates of the two points to be
    connected. *patchA* (or *patchB*) is given, the returned path is
    clipped so that it start (or end) from the boundary of the
    patch. The path is further shrunk by *shrinkA* (or *shrinkB*)
    which is given in points.
    c               @   s8   e Zd ZdZG dd dZdd Zdd Zdd
dZd	S )zConnectionStyle._Basea  
        A base class for connectionstyle classes. The subclass needs
        to implement a *connect* method whose call signature is::

          connect(posA, posB)

        where posA and posB are tuples of x, y coordinates to be
        connected.  The method needs to return a path connecting two
        points. This base class defines a __call__ method, and a few
        helper methods.
        c               @   s   e Zd Zdd ZdS )z!ConnectionStyle._Base.SimpleEventc             C   s   |\| _ | _d S )N)rH   rI   )r2   r   r9   r9   r:   r   }	  s    z*ConnectionStyle._Base.SimpleEvent.__init__N)r   r   r   r   r9   r9   r9   r:   SimpleEvent|	  s   r  c                s    r@ fdd}yt ||\}}W n tk
r:   |}Y nX |}rfdd}yt ||\}}W n tk
rz   |}Y nX |}|S )aI  
            Clip the path to the boundary of the patchA and patchB.
            The starting point of the path needed to be inside of the
            patchA and the end point inside the patch B. The *contains*
            methods of each patch object is utilized to test if the point
            is inside the path.
            c                s   t jj| } j|d S )Nr   )r  r  r  rX   )
xy_displayxy_event)patchAr9   r:   insideA	  s    z,ConnectionStyle._Base._clip.<locals>.insideAc                s   t jj| } j|d S )Nr   )r  r  r  rX   )r  r  )patchBr9   r:   insideB	  s    z,ConnectionStyle._Base._clip.<locals>.insideB)r   r'  )r2   r>   r  r  r  r"  r#  r  r9   )r  r  r:   _clip	  s    	

zConnectionStyle._Base._clipc             C   s   |r@t |jd |f }yt||\}}W n tk
r>   Y nX |rt |jd |f }yt||\}}W n tk
r~   Y nX |S )z]
            Shrink the path by fixed size (in points) with shrinkA and shrinkB.
            r   r   r  )r   rO   r   r'  )r2   r>   shrinkAshrinkBr  r"  r  r#  r9   r9   r:   _shrink	  s    zConnectionStyle._Base._shrink       @Nc       
      C   s,   | j ||}| j|||}| j|||}	|	S )z
            Call the *connect* method to create a path between *posA* and
            *posB*; then clip and shrink the path.
            )connectr  r  )
r2   posAposBr  r  r  r  r>   Zclipped_pathZshrunk_pathr9   r9   r:   r  	  s    zConnectionStyle._Base.__call__)r  r  NN)r   r   r   r   r  r  r  r  r9   r9   r9   r:   r  o	  s
   #r  c               @   s"   e Zd ZdZdddZdd ZdS )	zConnectionStyle.Arc3aM  
        Creates a simple quadratic Bezier curve between two
        points. The curve is created so that the middle control point
        (C1) is located at the same distance from the start (C0) and
        end points(C2) and the distance of the C1 to the line
        connecting C0-C2 is *rad* times the distance of C0-C2.
                c             C   s
   || _ dS )zE
            *rad*
              curvature of the curve.
            N)rad)r2   r  r9   r9   r:   r   	  s    zConnectionStyle.Arc3.__init__c             C   s   |\}}|\}}|| d || d  }}|| ||  }	}
| j }|||
  |||	   }}||f||f||fg}tjtjtjg}t||S )Ng       @)r  r   rR   r  )r2   r  r  r   r   x2y2Zx12Zy12r  r  fr,  cyrO   rN   r9   r9   r:   r  	  s    
zConnectionStyle.Arc3.connectN)r  )r   r   r   r   r   r  r9   r9   r9   r:   Arc3	  s   
r  c               @   s"   e Zd ZdZd	ddZdd ZdS )
zConnectionStyle.Angle3a
  
        Creates a simple quadratic Bezier curve between two
        points. The middle control points is placed at the
        intersecting point of two lines which cross the start and
        end point, and have a slope of angleA and angleB, respectively.
        Z   r   c             C   s   || _ || _dS )z
            *angleA*
              starting angle of the path

            *angleB*
              ending angle of the path
            N)angleAangleB)r2   r  r  r9   r9   r:   r   	  s    	zConnectionStyle.Angle3.__init__c          	   C   s   |\}}|\}}t jt j| j}t jt j| j}t jt j| j}	t jt j| j}
t|||||||	|
\}}||f||f||fg}tjtj	tj	g}t||S )N)
mathr=  radiansr  r>  r  r   r   rR   r  )r2   r  r  r   r   r  r  cosAsinAcosBsinBr,  r  rO   rN   r9   r9   r:   r  	  s    
zConnectionStyle.Angle3.connectN)r  r   )r   r   r   r   r   r  r9   r9   r9   r:   Angle3	  s   
r  c               @   s"   e Zd ZdZd
ddZdd Zd	S )zConnectionStyle.AngleaX  
        Creates a piecewise continuous quadratic Bezier path between
        two points. The path has a one passing-through point placed at
        the intersecting point of two lines which cross the start
        and end point, and have a slope of angleA and angleB, respectively.
        The connecting edges are rounded with *rad*.
        r  r           c             C   s   || _ || _|| _dS )z
            *angleA*
              starting angle of the path

            *angleB*
              ending angle of the path

            *rad*
              rounding radius of the edge
            N)r  r  r  )r2   r  r  r  r9   r9   r:   r   
  s    zConnectionStyle.Angle.__init__c          	   C   sp  |\}}|\}}t jt j| j}t jt j| j}t jt j| j}	t jt j| j}
t|||||||	|
\}}||fg}tjg}| j	dkr|j
||f |j
tj n|| ||  }}tj||}| j	| }|| ||  }}tj||}| j	| }|j|||  |||  f||f|||  |||  fg |jtjtjtjg |j
||f |j
tj t||S )Ng        )r  r=  r  r  r>  r  r   r   rR   r  appendr  rP   r  extendr  )r2   r  r  r   r   r  r  r  r  r  r  r,  r  rO   rN   dx1dy1Zd1f1dx2dy2Zd2f2r9   r9   r:   r  %
  s4    




zConnectionStyle.Angle.connectN)r  r   r  )r   r   r   r   r   r  r9   r9   r9   r:   Angle

  s   
r  c               @   s"   e Zd ZdZd	ddZdd ZdS )
zConnectionStyle.Arca:  
        Creates a piecewise continuous quadratic Bezier path between
        two points. The path can have two passing-through points, a
        point placed at the distance of armA and angle of angleA from
        point A, another point with respect to point B. The edges are
        rounded with *rad*.
        r   N        c             C   s"   || _ || _|| _|| _|| _dS )aH  
            *angleA* :
              starting angle of the path

            *angleB* :
              ending angle of the path

            *armA* :
              length of the starting arm

            *armB* :
              length of the ending arm

            *rad* :
              rounding radius of the edges
            N)r  r  armAarmBr  )r2   r  r  r  r  r  r9   r9   r:   r   R
  s
    zConnectionStyle.Arc.__init__c             C   sv  |\}}|\}}||fg}g }t jg}	| jrtjtj| j}
tjtj| j}| j| j }|j	|||
  |||  f | j}|j	|||
  |||  f | j
rtjtj| j}tjtj| j}|| j
|  || j
|   }}|rl|d \}}|| ||  }}|| ||  d }|j	|| j| |  || j| |  f |j| |	jt jt jt jg n2|d \}}|| ||  }}|| ||  d }|| j }||| |  ||| |  f||fg}|rR|d \}}|| ||  }}|| ||  d }|j	|| j| |  || j| |  f |j| |	jt jt jt jg |j	||f |	j	t j t ||	S )Nr   g      ?r  r  r  )r   rR   r  r  r=  r  r  r>  r  r  r  r  r  r  r  )r2   r  r  r   r   r  r  rO   ZroundedrN   r  r  dr  r  Zx_armBZy_armBZxpZypr  r  ddr9   r9   r:   r  k
  sZ    





zConnectionStyle.Arc.connect)r   r   NNr  )r   r   r   r   r   r  r9   r9   r9   r:   r   H
  s   
r   c               @   s"   e Zd ZdZd	ddZdd ZdS )
zConnectionStyle.Bara  
        A line with *angle* between A and B with *armA* and
        *armB*. One of the arms is extended so that they are connected in
        a right angle. The length of armA is determined by (*armA*
        + *fraction* x AB distance). Same for armB.
                333333?Nc             C   s   || _ || _|| _|| _dS )a  
            Parameters
            ----------
            armA : float
                minimum length of armA

            armB : float
                minimum length of armB

            fraction : float
                a fraction of the distance between two points that
                will be added to armA and armB.

            angle : float or None
                angle of the connecting line (if None, parallel
                to A and B)
            N)r  r  fractionr   )r2   r  r  r  r   r9   r9   r:   r   
  s    zConnectionStyle.Bar.__init__c             C   s  |\}}| \}}\}}t j|| || }	|| ||  }
}|
|
 ||  d }|
| ||  }}| j| j }}| jd k	rtj| j}|	| }|t j| }|t j| }||t j|  ||t j|   }}|| }|| ||  }
}|
|
 ||  d }|
| ||  }}t	||}| j
| | }|||  |||   }}|||  |||   }}||f||f||f||fg}tjtjtjtjg}t||S )Ng      ?)r  atan2r  r  r   rP   r<  r>  r=  rz  r  r   rR   r  )r2   r  r  r   r   Zx20Zy20r  r  r  r  r  r  ddxddyr  r  Ztheta0ZdthetadlZdLZdd2armr  Zcx1Zcy1Zcx2Zcy2rO   rN   r9   r9   r:   r  
  s<    &

zConnectionStyle.Bar.connect)r  r  r  N)r   r   r   r   r   r  r9   r9   r9   r:   Bar
  s   
r  N)r   r   r   r   rh  r  r  r  r  r  r   r  r9   r9   r9   r:   r  H	  s   #Q#%=]r  c       
      C   sL   | | ||  }}||| ||  d  }| ||  |||   }}	||	fS )z{
    Return the point on the line connecting (*x0*, *y0*) -- (*x1*, *y1*) whose
    distance from (*x0*, *y0*) is *d*.
    g      ?r9   )
r   r   r   r   r  r  r  ffr  r  r9   r9   r:   _point_along_a_line
  s    r  c               @   s  e Zd ZdZi ZG dd dZG dd deZeeddG dd	 d	eZeed
dG dd deZ	eeddG dd deZ
eeddG dd deZeeddG dd deZeeddG dd deZeeddG dd deZG dd deZeeddG dd  d eZeed!dG d"d# d#eZeed$dG d%d& d&eZeed'dG d(d) d)eZeeG d*d+ d+eZeeG d,d- d-eZeeG d.d/ d/eZd0S )1
ArrowStylea  
    `ArrowStyle` is a container class which defines several
    arrowstyle classes, which is used to create an arrow path along a
    given path.  These are mainly used with `FancyArrowPatch`.

    A arrowstyle object can be either created as::

           ArrowStyle.Fancy(head_length=.4, head_width=.4, tail_width=.4)

    or::

           ArrowStyle("Fancy", head_length=.4, head_width=.4, tail_width=.4)

    or::

           ArrowStyle("Fancy, head_length=.4, head_width=.4, tail_width=.4")

    The following classes are defined

    %(AvailableArrowstyles)s

    An instance of any arrow style class is a callable object,
    whose call signature is::

        __call__(self, path, mutation_size, linewidth, aspect_ratio=1.)

    and it returns a tuple of a `.Path` instance and a boolean
    value. *path* is a `.Path` instance along which the arrow
    will be drawn. *mutation_size* and *aspect_ratio* have the same
    meaning as in `BoxStyle`. *linewidth* is a line width to be
    stroked. This is meant to be used to correct the location of the
    head so that it does not overshoot the destination point, but not all
    classes support it.
    c               @   s.   e Zd ZdZedd Zdd Zd
ddZd	S )zArrowStyle._Basea  
        Arrow Transmuter Base class

        ArrowTransmuterBase and its derivatives are used to make a fancy
        arrow around a given path. The __call__ method returns a path
        (which will be used to create a PathPatch instance) and a boolean
        value indicating the path is open therefore is not fillable.  This
        class is not an artist and actual drawing of the fancy arrow is
        done by the FancyArrowPatch class.

        c             C   s\   t | j }t|dks<|d d tjks<|d d tjkrDtd|d d |d d S )a4  
            Some ArrowStyle class only works with a simple quadratic Bezier
            curve (created with Arc3Connection or Angle3Connector). This static
            method is to check if the provided path is a simple quadratic
            Bezier curve and returns its control points if true.
            r  r   r   z,'path' is not a valid quadratic Bezier curve)listZiter_segmentsr0   r   rR   r  r'  )r>   segmentsr9   r9   r:   ensure_quadratic_bezier3  s    z(ArrowStyle._Base.ensure_quadratic_bezierc             C   s   t ddS )a  
            The transmute method is the very core of the ArrowStyle class and
            must be overridden in the subclasses. It receives the path object
            along which the arrow will be drawn, and the mutation_size, with
            which the arrow head etc. will be scaled. The linewidth may be
            used to adjust the path so that it does not pass beyond the given
            points. It returns a tuple of a Path instance and a boolean. The
            boolean value indicate whether the path can be filled or not. The
            return value can also be a list of paths and list of booleans of a
            same length.
            zDerived must overrideN)r   )r2   r>   r  r   r9   r9   r:   r  B  s    zArrowStyle._Base.transmute      ?c             C   s   |dk	r|j d|g }t||j}| j|||\}}tj|rxg }	x,t|D ] }
|	jt|
j d|g |
j qLW |	|fS ||fS n| j|||S dS )z
            The __call__ method is a thin wrapper around the transmute method
            and takes care of the aspect ratio.
            Nr   )rO   r   rN   r  rP   iterablerO  r  )r2   r>   r  r   r  rO   Zpath_shrunkZpath_mutatedfillable	path_listr  r9   r9   r:   r  P  s    


zArrowStyle._Base.__call__N)r  )r   r   r   r   staticmethodr  r  r  r9   r9   r9   r:   r  "  s   r  c                   s2   e Zd ZdZd fdd	Zdd	 Zd
d Z  ZS )zArrowStyle._Curvea*  
        A simple arrow which will work with any path instance. The
        returned path is simply concatenation of the original path + at
        most two paths representing the arrow head at the begin point and the
        at the end point. The arrow heads can be either open or closed.
        NF皙?皙?c                s8   || | _ | _|| | _| _|| | _| _t j  dS )a>  
            The arrows are drawn if *beginarrow* and/or *endarrow* are
            true. *head_length* and *head_width* determines the size
            of the arrow relative to the *mutation scale*.  The
            arrowhead at the begin (or end) is closed if fillbegin (or
            fillend) is True.
            N)
beginarrowendarrowr*  r)  	fillbeginfillendru   r   )r2   r  r  r  r  r*  r)  )rw   r9   r:   r   s  s    
zArrowStyle._Curve.__init__c	             C   s  || ||  }	}
t j|	|
}d| | }|dkr6d}||	 | }||
 | }|	| | }	|
| | }
||	 ||
  | |	 ||
   }}||	 ||
  ||	 ||
   }}|| | || | f|| || f|| | || | fg}tjtjtjg}||||fS )a  
            Return the paths for arrow heads. Since arrow lines are
            drawn with capstyle=projected, The arrow goes beyond the
            desired point. This method also returns the amount of the path
            to be shrunken so that it does not overshoot.
            g      ?r   r   )rP   r  r   rR   r  )r2   r   r   r   r   	head_distcos_tsin_tr   r  r  Zcp_distanceZpad_projectedr  r  r  r  r  r  vertices_arrowcodes_arrowr9   r9   r:   _get_arrow_wedge  s$    
$"z"ArrowStyle._Curve._get_arrow_wedgec          	   C   s,  | j | }| j| }tj||}|| ||  }}|jd \}	}
|jd \}}| job|	|
f||fk}|r| j|||	|
||||n
g g ddf\}}}}|jd \}}|jd \}}| jo||f||fk}|r| j||||||||n
g g ddf\}}}}ttj	|	| |
| fg|jdd || || fgg|j
g}dg}|r| jrtj	||d |d gg}tj	|tjtjgg}|jt|| |jd n|jt|| |jd |r$| jr
|jd tj	||d |d gg}tj	|tjtjgg}|jt|| n|jd |jt|| ||fS )	Nr   r   r  FTr$  r  r  )r*  r)  rP   r  rO   r  r  r  r   r  rN   r  r  r  r  r  )r2   r>   r  r   r*  r)  r  r  r  r   r   r   r   Zhas_begin_arrow	verticesAcodesAZddxAZddyAr  r  Zx3Zy3Zhas_end_arrow	verticesBcodesBZddxBZddyBr   Z	_fillabler  rt   r9   r9   r:   r    sL    





zArrowStyle._Curve.transmute)NNFFr  r  )r   r   r   r   r   r  r  r   r9   r9   )rw   r:   _Curvek  s     *r  -)rx  c                   s    e Zd ZdZ fddZ  ZS )zArrowStyle.Curvez&A simple curve without any arrow head.c                s   t  jddd d S )NF)r  r  )ru   r   )r2   )rw   r9   r:   r     s    zArrowStyle.Curve.__init__)r   r   r   r   r   r   r9   r9   )rw   r:   Curve  s   r  z<-c                   s"   e Zd ZdZd fdd	Z  ZS )zArrowStyle.CurveAz(An arrow with a head at its begin point.皙?皙?c                s   t  jdd||d dS )z
            Parameters
            ----------
            head_length : float, default: 0.4
                Length of the arrow head.

            head_width : float, default: 0.2
                Width of the arrow head.
            TF)r  r  r*  r)  N)ru   r   )r2   r*  r)  )rw   r9   r:   r     s    

zArrowStyle.CurveA.__init__)r  r  )r   r   r   r   r   r   r9   r9   )rw   r:   CurveA  s   r	  z->c                   s"   e Zd ZdZd fdd	Z  ZS )zArrowStyle.CurveBz&An arrow with a head at its end point.皙?皙?c                s   t  jdd||d dS )z
            Parameters
            ----------
            head_length : float, default: 0.4
                Length of the arrow head.

            head_width : float, default: 0.2
                Width of the arrow head.
            FT)r  r  r*  r)  N)ru   r   )r2   r*  r)  )rw   r9   r:   r   	  s    

zArrowStyle.CurveB.__init__)r
  r  )r   r   r   r   r   r   r9   r9   )rw   r:   CurveB  s   r  z<->c                   s"   e Zd ZdZd fdd	Z  ZS )zArrowStyle.CurveABz8An arrow with heads both at the begin and the end point.皙?皙?c                s   t  jdd||d dS )z
            Parameters
            ----------
            head_length : float, default: 0.4
                Length of the arrow head.

            head_width : float, default: 0.2
                Width of the arrow head.
            T)r  r  r*  r)  N)ru   r   )r2   r*  r)  )rw   r9   r:   r     s    

zArrowStyle.CurveAB.__init__)r  r  )r   r   r   r   r   r   r9   r9   )rw   r:   CurveAB  s   r  z<|-c                   s"   e Zd ZdZd fdd	Z  ZS )zArrowStyle.CurveFilledAz0An arrow with filled triangle head at the begin.皙?皙?c                s   t  jdddd||d dS )z
            Parameters
            ----------
            head_length : float, default: 0.4
                Length of the arrow head.

            head_width : float, default: 0.2
                Width of the arrow head.
            TF)r  r  r  r  r*  r)  N)ru   r   )r2   r*  r)  )rw   r9   r:   r   +  s    

z ArrowStyle.CurveFilledA.__init__)r  r  )r   r   r   r   r   r   r9   r9   )rw   r:   CurveFilledA'  s   r  z-|>c                   s"   e Zd ZdZd fdd	Z  ZS )zArrowStyle.CurveFilledBz.An arrow with filled triangle head at the end.皙?皙?c                s   t  jdddd||d dS )z
            Parameters
            ----------
            head_length : float, default: 0.4
                Length of the arrow head.

            head_width : float, default: 0.2
                Width of the arrow head.
            FT)r  r  r  r  r*  r)  N)ru   r   )r2   r*  r)  )rw   r9   r:   r   =  s    

z ArrowStyle.CurveFilledB.__init__)r  r  )r   r   r   r   r   r   r9   r9   )rw   r:   CurveFilledB9  s   r  z<|-|>c                   s"   e Zd ZdZd fdd	Z  ZS )zArrowStyle.CurveFilledABz1An arrow with filled triangle heads at both ends.皙?皙?c                s   t  jdddd||d dS )z
            Parameters
            ----------
            head_length : float, default: 0.4
                Length of the arrow head.

            head_width : float, default: 0.2
                Width of the arrow head.
            T)r  r  r  r  r*  r)  N)ru   r   )r2   r*  r)  )rw   r9   r:   r   O  s    

z!ArrowStyle.CurveFilledAB.__init__)r  r  )r   r   r   r   r   r   r9   r9   )rw   r:   CurveFilledABK  s   r  c            
   @   s&   e Zd Zd
ddZdd Zdd	 ZdS )zArrowStyle._BracketN      ?皙?c             C   sJ   || | _ | _|| | _| _|| | _| _|| | _| _|	|
 | _| _	d S )N)
bracketAbracketBwidthAwidthBlengthAlengthBr  r  scaleAscaleB)r2   r  r  r  r  r  r   r  r  r!  r"  r9   r9   r:   r   _  s
    zArrowStyle._Bracket.__init__c             C   s~   ddl m} ||||||\}}	}
}|| ||  }}|| |	| f||	f|
|f|
| || fg}tjtjtjtjg}||fS )Nr   )get_normal_points)Zmatplotlib.bezierr#  r   rR   r  )r2   r   r   r  r  r   r+  r#  r   r   r  r  r  r  r  r  r9   r9   r:   _get_bracketj  s    z ArrowStyle._Bracket._get_bracketc             C   sN  | j d kr|}n| j }| jd kr&|}n| j}g g  }}| jr|jd \}}	|jd \}
}t|
|||	\}}| j||	||| j| | j| \}}|j| |j| |j|j |j|j	 | j
r(|jd \}}	|jd \}
}t|
|||	\}}| j||	||| j| | j| \}}|j| |j| tj|}tj|}t||}|dfS )Nr   r   r  Fr  r$  )r!  r"  r  rO   r   r$  r  r  r  rN   r  r  r   rP   r  r   )r2   r>   r  r   r!  r"  Zvertices_listZ
codes_listr   r   r   r   r  r  r   r  r  r  rO   rN   r  r9   r9   r:   r  ~  s>    









zArrowStyle._Bracket.transmute)
NNr  r  r  r  NNNN)r   r   r   r   r$  r  r9   r9   r9   r:   _Bracket]  s       
r%  z]-[c                   s"   e Zd ZdZd fdd	Z  ZS )zArrowStyle.BracketABz3An arrow with outward square brackets at both ends.      ?皙?Nc          
      s    t  jdd||||||d dS )aD  
            Parameters
            ----------
            widthA : float, default: 1.0
                Width of the bracket.

            lengthA : float, default: 0.2
                Length of the bracket.

            angleA : float, default: None
                Angle between the bracket and the line.

            widthB : float, default: 1.0
                Width of the bracket.

            lengthB : float, default: 0.2
                Length of the bracket.

            angleB : float, default: None
                Angle between the bracket and the line.
            T)r  r  r  r  r   r  N)ru   r   )r2   r  r  r  r  r   r  )rw   r9   r:   r     s    
zArrowStyle.BracketAB.__init__)r&  r'  Nr&  r'  N)r   r   r   r   r   r   r9   r9   )rw   r:   	BracketAB  s    r(  z]-c                   s"   e Zd ZdZd fdd	Z  ZS )zArrowStyle.BracketAz5An arrow with an outward square bracket at its start.      ?皙?Nc                s   t  jdd|||d dS )a?  
            Parameters
            ----------
            widthA : float, default: 1.0
                Width of the bracket.

            lengthA : float, default: 0.2
                Length of the bracket.

            angleA : float, default: None
                Angle between the bracket and the line.
            TN)r  r  r  )ru   r   )r2   r  r  r  )rw   r9   r:   r     s    
zArrowStyle.BracketA.__init__)r)  r*  N)r   r   r   r   r   r   r9   r9   )rw   r:   BracketA  s   r+  z-[c                   s"   e Zd ZdZd fdd	Z  ZS )zArrowStyle.BracketBz3An arrow with an outward square bracket at its end.      ?皙?Nc                s   t  jdd|||d dS )a?  
            Parameters
            ----------
            widthB : float, default: 1.0
                Width of the bracket.

            lengthB : float, default: 0.2
                Length of the bracket.

            angleB : float, default: None
                Angle between the bracket and the line.
            NT)r  r   r  )ru   r   )r2   r  r   r  )rw   r9   r:   r     s    
zArrowStyle.BracketB.__init__)r,  r-  N)r   r   r   r   r   r   r9   r9   )rw   r:   BracketB  s   r.  z|-|c                   s"   e Zd ZdZd fdd	Z  ZS )zArrowStyle.BarABz/An arrow with vertical bars ``|`` at both ends.      ?Nc          
      s    t  jdd|d||d|d dS )a  
            Parameters
            ----------
            widthA : float, default: 1.0
                Width of the bracket.

            angleA : float, default: None
                Angle between the bracket and the line.

            widthB : float, default: 1.0
                Width of the bracket.

            angleB : float, default: None
                Angle between the bracket and the line.
            Tr   )r  r  r  r  r   r  N)ru   r   )r2   r  r  r  r  )rw   r9   r:   r     s    
zArrowStyle.BarAB.__init__)r/  Nr/  N)r   r   r   r   r   r   r9   r9   )rw   r:   BarAB  s    r0  c                   s*   e Zd ZdZd fdd	Zdd Z  ZS )	zArrowStyle.Simplez9A simple arrow. Only works with a quadratic Bezier curve.      ?皙?c                s$   |||  | _ | _| _t j  dS )aA  
            Parameters
            ----------
            head_length : float, default: 0.5
                Length of the arrow head.

            head_width : float, default: 0.5
                Width of the arrow head.

            tail_width : float, default: 0.2
                Width of the arrow tail.
            N)r*  r)  
tail_widthru   r   )r2   r*  r)  r3  )rw   r9   r:   r     s    zArrowStyle.Simple.__init__c             C   s  | j |\}}}}}}	| j| }
t||	|
}||f||f||	fg}yt||dd\}}W n\ tk
r   t||	|||
\}}d||  d||	   }}||f||f||	fg}d }Y nX | j| }t||d dd\}}|d k	r| j| }t	||d \}}t
j|d ft
j|d ft
j|d ft
j|d ft
j|d ft
j|d ft
j|d ft
j|d ft
j|d ft
j|d ft
j|d ft
j|d ft
j|d fg}nLt
j|d ft
j|d ft
j|d ft
j|d ft
j|d ft
j|d fg}t
d	d
 |D dd
 |D }|dfS )Ng{Gz?)	toleranceg      ?g       @)wmr   r   r  c             S   s   g | ]\}}|qS r9   r9   )rJ   rt   r  r9   r9   r:   rd  X  s    z/ArrowStyle.Simple.transmute.<locals>.<listcomp>c             S   s   g | ]\}}|qS r9   r9   )rJ   rt   r  r9   r9   r:   rd  X  s    T)r  r*  r   r   r
   r  r)  r   r3  r   r   rR   r  r  r  )r2   r>   r  r   r   r   r   r   r  r  r*  in_f
arrow_pathZ	arrow_outZarrow_inx1ny1nr)  	head_left
head_rightr3  	tail_left
tail_right
patch_pathr9   r9   r:   r  !  sP    




zArrowStyle.Simple.transmute)r1  r1  r2  )r   r   r   r   r   r  r   r9   r9   )rw   r:   Simple  s   r?  c                   s*   e Zd ZdZd fdd	Zdd Z  ZS )zArrowStyle.Fancyz8A fancy arrow. Only works with a quadratic Bezier curve.皙?c                s$   |||  | _ | _| _t j  dS )aA  
            Parameters
            ----------
            head_length : float, default: 0.4
                Length of the arrow head.

            head_width : float, default: 0.4
                Width of the arrow head.

            tail_width : float, default: 0.4
                Width of the arrow tail.
            N)r*  r)  r3  ru   r   )r2   r*  r)  r3  )rw   r9   r:   r   `  s    zArrowStyle.Fancy.__init__c             C   s  | j |\}}}}}}	| j| }
||f||f||	fg}t||	|
}yt||dd\}}W n\ tk
r   t||	|||
\}}d||  d||	   }}||f||f||	fg}|}Y nX |}t||	|
d }t||dd\}}|}| j| }t||d dd\}}| j| }t||d ddd	d
\}}t|||d	 }t||dd\}}|d }|| }}t	j
|ft	j|d ft	j|d ft	j|d ft	j|d ft	j|d ft	j|d ft	j|d ft	j|d ft	j|d ft	j|d ft	j|d ft	j|ft	j|fg}t	dd |D dd |D }|dfS )Ng{Gz?)r4  g      ?g?g       @g333333?)r5  g      ?g333333?)Zw1r5  Zw2r   r   r  c             S   s   g | ]\}}|qS r9   r9   )rJ   rt   r  r9   r9   r:   rd    s    z.ArrowStyle.Fancy.transmute.<locals>.<listcomp>c             S   s   g | ]\}}|qS r9   r9   )rJ   rt   r  r9   r9   r:   rd    s    Tr  )r  r*  r   r   r
   r  r)  r   r3  r   rR   r  r  r  )r2   r>   r  r   r   r   r   r   r  r  r*  r7  r6  Zpath_outZpath_inr8  r9  Z	path_headZ	path_tailr)  Zhead_lZhead_rr3  r<  r=  Z
tail_startr;  r:  r>  r9   r9   r:   r  q  s\    




zArrowStyle.Fancy.transmute)r@  r@  r@  )r   r   r   r   r   r  r   r9   r9   )rw   r:   Fancy\  s   rA  c                   s*   e Zd ZdZd fdd	Zdd Z  ZS )	zArrowStyle.Wedgez
        Wedge(?) shape. Only works with a quadratic Bezier curve.  The
        begin point has a width of the tail_width and the end point has a
        width of 0. At the middle, the width is shrink_factor*tail_width.
        333333?      ?c                s   || _ || _t j  dS )z
            Parameters
            ----------
            tail_width : float, default: 0.3
                Width of the tail.

            shrink_factor : float, default: 0.5
                Fraction of the arrow width at the middle point.
            N)r3  shrink_factorru   r   )r2   r3  rD  )rw   r9   r:   r     s    
zArrowStyle.Wedge.__init__c          	   C   s   | j |\}}}}}}	||f||f||	fg}
t|
| j| d | jd\}}tj|d ftj|d ftj|d ftj|d ftj|d ftj|d ftj|d fg}tdd |D dd |D }|d	fS )
Ng       @)r5  r   r   r  c             S   s   g | ]\}}|qS r9   r9   )rJ   rt   r  r9   r9   r:   rd    s    z.ArrowStyle.Wedge.transmute.<locals>.<listcomp>c             S   s   g | ]\}}|qS r9   r9   )rJ   rt   r  r9   r9   r:   rd    s    T)	r  r   r3  rD  r   rR   r  r  r  )r2   r>   r  r   r   r   r   r   r  r  r7  Zb_plusZb_minusr>  r9   r9   r:   r    s    zArrowStyle.Wedge.transmute)rB  rC  )r   r   r   r   r   r  r   r9   r9   )rw   r:   r     s   r   N)r   r   r   r   rh  r  r  r  r  r	  r  r  r  r  r  r%  r(  r+  r.  r0  r?  rA  r   r9   r9   r9   r:   r  
  sD   "I MOWr  )ZAvailableBoxstylesZListBoxstylesZAvailableArrowstylesZAvailableConnectorstylesc               @   s   e Zd ZdZdZdd Zejd,dd	Zejd-d
dZ	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ ZdS ).r   aO  
    A fancy box around a rectangle with lower left at *xy* = (*x*, *y*)
    with specified width and height.

    `.FancyBboxPatch` is similar to `.Rectangle`, but it draws a fancy box
    around the rectangle. The transformation of the rectangle box to the
    fancy box is delegated to the style classes defined in `.BoxStyle`.
    Tc             C   s$   | j jd }|| j| j| j| jf S )Nz((%g, %g), width=%g, height=%g))rw   r   _x_yr   r   )r2   r   r9   r9   r:   r     s    zFancyBboxPatch.__str__r  N      ?c       	      K   sn   t j| f| |d | _|d | _|| _|| _|dkrN|dkrFtd|| _n
| j| || _	|| _
d| _dS )a  
        Parameters
        ----------
        xy : float, float
          The lower left corner of the box.

        width : float
            The width of the box.

        height : float
            The height of the box.

        boxstyle : str or `matplotlib.patches.BoxStyle`
            The style of the fancy box. This can either be a `.BoxStyle`
            instance or a string of the style name and optionally comma
            seprarated attributes (e.g. "Round, pad=0.2"). This string is
            passed to `.BoxStyle` to construct a `.BoxStyle` object. See
            there for a full documentation.

            The following box styles are available:

            %(AvailableBoxstyles)s

        mutation_scale : float, default: 1
            Scaling factor applied to the attributes of the box style
            (e.g. pad or rounding_size).

        mutation_aspect : float, optional
            The height of the rectangle will be squeezed by this value before
            the mutation and the mutated box will be stretched by the inverse
            of it. For example, this allows different horizontal and vertical
            padding.

        Other Parameters
        ----------------
        **kwargs : `.Patch` properties

        %(Patch)s
        r   r   ZcustomNz7bbox_transmuter argument is needed with custom boxstyleT)r   r   rE  rF  r   r   r'  _bbox_transmuterset_boxstyle_mutation_scale_mutation_aspectrl   )	r2   r   r   r   boxstyleZbbox_transmutermutation_scalemutation_aspectr8   r9   r9   r:   r     s    /


zFancyBboxPatch.__init__c             K   sD   |dkrt j S t|t js$t|r,|| _nt |f|| _d| _dS )a  
        Set the box style.

        Most box styles can be further configured using attributes.
        Attributes from the previous box style are not reused.

        Without argument (or with ``boxstyle=None``), the available box styles
        are returned as a human-readable string.

        Parameters
        ----------
        boxstyle : str
            The name of the box style. Optionally, followed by a comma and a
            comma-separated list of attributes. The attributes may
            alternatively be passed separately as keyword arguments.

            The following box styles are available:

            %(AvailableBoxstyles)s

            .. ACCEPTS: %(ListBoxstyles)s

        **kwargs
            Additional attributes for the box style. See the table above for
            supported parameters.

        Examples
        --------
        ::

            set_boxstyle("round,pad=0.2")
            set_boxstyle("round", pad=0.2)

        NT)r  r  rA   r  callablerH  rl   )r2   rL  r8   r9   r9   r:   rI  ?  s    $zFancyBboxPatch.set_boxstylec             C   s   || _ d| _dS )zf
        Set the mutation scale.

        Parameters
        ----------
        scale : float
        TN)rJ  rl   )r2   r   r9   r9   r:   set_mutation_scalel  s    z!FancyBboxPatch.set_mutation_scalec             C   s   | j S )zReturn the mutation scale.)rJ  )r2   r9   r9   r:   get_mutation_scalew  s    z!FancyBboxPatch.get_mutation_scalec             C   s   || _ d| _dS )zz
        Set the aspect ratio of the bbox mutation.

        Parameters
        ----------
        aspect : float
        TN)rK  rl   )r2   aspectr9   r9   r:   set_mutation_aspect{  s    z"FancyBboxPatch.set_mutation_aspectc             C   s   | j S )z-Return the aspect ratio of the bbox mutation.)rK  )r2   r9   r9   r:   get_mutation_aspect  s    z"FancyBboxPatch.get_mutation_aspectc             C   s   | j S )zReturn the boxstyle object.)rH  )r2   r9   r9   r:   get_boxstyle  s    zFancyBboxPatch.get_boxstylec             C   s*   | j  | j| j| j| j| j | j }|S )z)Return the mutated path of the rectangle.)rU  rE  rF  r   r   rQ  rT  )r2   r   r9   r9   r:   r<     s
    
zFancyBboxPatch.get_pathc             C   s   | j S )z'Return the left coord of the rectangle.)rE  )r2   r9   r9   r:   r     s    zFancyBboxPatch.get_xc             C   s   | j S )z)Return the bottom coord of the rectangle.)rF  )r2   r9   r9   r:   r     s    zFancyBboxPatch.get_yc             C   s   | j S )z"Return the width of the rectangle.)r   )r2   r9   r9   r:   r     s    zFancyBboxPatch.get_widthc             C   s   | j S )z#Return the height of the rectangle.)r   )r2   r9   r9   r:   r     s    zFancyBboxPatch.get_heightc             C   s   || _ d| _dS )zo
        Set the left coord of the rectangle.

        Parameters
        ----------
        x : float
        TN)rE  rl   )r2   rH   r9   r9   r:   r     s    zFancyBboxPatch.set_xc             C   s   || _ d| _dS )zq
        Set the bottom coord of the rectangle.

        Parameters
        ----------
        y : float
        TN)rF  rl   )r2   rI   r9   r9   r:   r     s    zFancyBboxPatch.set_yc             C   s   || _ d| _dS )zc
        Set the rectangle width.

        Parameters
        ----------
        w : float
        TN)r   rl   )r2   r}   r9   r9   r:   r     s    zFancyBboxPatch.set_widthc             C   s   || _ d| _dS )zd
        Set the rectangle height.

        Parameters
        ----------
        h : float
        TN)r   rl   )r2   r   r9   r9   r:   r     s    zFancyBboxPatch.set_heightc             G   sL   t |dkr|d \}}}}n|\}}}}|| _|| _|| _|| _d| _dS )a  
        Set the bounds of the rectangle.

        Call signatures::

            set_bounds(left, bottom, width, height)
            set_bounds((left, bottom, width, height))

        Parameters
        ----------
        left, bottom : float
            The coordinates of the bottom left corner of the rectangle.
        width, height : float
            The width/height of the rectangle.
        r   r   TN)r0   rE  rF  r   r   rl   )r2   r   r   r   r}   r   r9   r9   r:   r     s    zFancyBboxPatch.set_boundsc             C   s   t jj| j| j| j| jS )zReturn the `.Bbox`.)r	   r   Zfrom_boundsrE  rF  r   r   )r2   r9   r9   r:   r     s    zFancyBboxPatch.get_bbox)r  NrG  N)N)r   r   r   r   rn   r   r   r   r   rI  rP  rQ  rS  rT  rU  r<   r   r   r   r   r   r   r   r   r   r   r9   r9   r9   r:   r     s4      >,
c               @   s   e Zd ZdZdZdd Zejd,d
dZdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zd-ddZdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ ZdS ).FancyArrowPatcha  
    A fancy arrow patch. It draws an arrow using the `ArrowStyle`.

    The head and tail positions are fixed at the specified start and end points
    of the arrow, but the size and shape (in display coordinates) of the arrow
    does not change when the axis is moved or zoomed.
    Tc          
   C   sh   | j d k	rL| j \\}}\}}t| j d|dd|dd|dd|dd
S t| j d| j dS d S )Nz((gz, z)->(z))())
_posA_posBtyper   _path_original)r2   r   r   r  r  r9   r9   r:   r     s    
0zFancyArrowPatch.__str__Nsimplearc3r  r   c             K   s   |j dd |j dd tj| f| |dk	r`|dk	r`|dkr`||g| _|dkrTd}| j| n(|dkr|dkr|dk	rd| _ntd|| _|| _|| _|	| _	|| _
| j| |
| _|| _| j| dS )a  
        There are two ways for defining an arrow:

        - If *posA* and *posB* are given, a path connecting two points is
          created according to *connectionstyle*. The path will be
          clipped with *patchA* and *patchB* and further shrunken by
          *shrinkA* and *shrinkB*. An arrow is drawn along this
          resulting path using the *arrowstyle* parameter.

        - Alternatively if *path* is provided, an arrow is drawn along this
          path and *patchA*, *patchB*, *shrinkA*, and *shrinkB* are ignored.

        Parameters
        ----------
        posA, posB : (float, float), default: None
            (x, y) coordinates of arrow tail and arrow head respectively.

        path : `~matplotlib.path.Path`, default: None
            If provided, an arrow is drawn along this path and *patchA*,
            *patchB*, *shrinkA*, and *shrinkB* are ignored.

        arrowstyle : str or `.ArrowStyle`, default: 'simple'
            The `.ArrowStyle` with which the fancy arrow is drawn.  If a
            string, it should be one of the available arrowstyle names, with
            optional comma-separated attributes.  The optional attributes are
            meant to be scaled with the *mutation_scale*.  The following arrow
            styles are available:

            %(AvailableArrowstyles)s

        connectionstyle : str or `.ConnectionStyle` or None, optional, default: 'arc3'
            The `.ConnectionStyle` with which *posA* and *posB* are connected.
            If a string, it should be one of the available connectionstyle
            names, with optional comma-separated attributes.  The following
            connection styles are available:

            %(AvailableConnectorstyles)s

        patchA, patchB : `.Patch`, default: None
            Head and tail patches, respectively.

        shrinkA, shrinkB : float, default: 2
            Shrinking factor of the tail and head of the arrow respectively.

        mutation_scale : float, default: 1
            Value with which attributes of *arrowstyle* (e.g., *head_length*)
            will be scaled.

        mutation_aspect : None or float, default: None
            The height of the rectangle will be squeezed by this value before
            the mutation and the mutated box will be stretched by the inverse
            of it.

        dpi_cor : float, default: 1
            dpi_cor is currently used for linewidth-related things and shrink
            factor. Mutation scale is affected by this.

        Other Parameters
        ----------------
        **kwargs : `.Patch` properties, optional
            Here is a list of available `.Patch` properties:

        %(Patch)s

            In contrast to other patches, the default ``capstyle`` and
            ``joinstyle`` for `FancyArrowPatch` are set to ``"round"``.
        r7   r  r6   Nr^  z.Either posA and posB, or path need to provided)r:  r   r   rZ  set_connectionstyler'  r  r  r  r  r\  set_arrowstylerJ  rK  set_dpi_cor)r2   r  r  r>   
arrowstyleconnectionstyler  r  r  r  rM  rN  dpi_corr8   r9   r9   r:   r     s(    R

zFancyArrowPatch.__init__c             C   s   || _ d| _dS )z
        dpi_cor is currently used for linewidth-related things and
        shrink factor. Mutation scale is affected by this.

        Parameters
        ----------
        dpi_cor : float
        TN)_dpi_corrl   )r2   rd  r9   r9   r:   ra  v  s    	zFancyArrowPatch.set_dpi_corc             C   s   | j S )z
        dpi_cor is currently used for linewidth-related things and
        shrink factor. Mutation scale is affected by this.

        Returns
        -------
        scalar
        )re  )r2   r9   r9   r:   get_dpi_cor  s    	zFancyArrowPatch.get_dpi_corc             C   s.   |dk	r|| j d< |dk	r$|| j d< d| _dS )a  
        Set the begin and end positions of the connecting path.

        Parameters
        ----------
        posA, posB : None, tuple
            (x, y) coordinates of arrow tail and arrow head respectively. If
            `None` use current value.
        Nr   r   T)rZ  rl   )r2   r  r  r9   r9   r:   set_positions  s
    


zFancyArrowPatch.set_positionsc             C   s   || _ d| _dS )zn
        Set the tail patch.

        Parameters
        ----------
        patchA : `.patches.Patch`
        TN)r  rl   )r2   r  r9   r9   r:   
set_patchA  s    zFancyArrowPatch.set_patchAc             C   s   || _ d| _dS )zn
        Set the head patch.

        Parameters
        ----------
        patchB : `.patches.Patch`
        TN)r  rl   )r2   r  r9   r9   r:   
set_patchB  s    zFancyArrowPatch.set_patchBc             K   sD   |dkrt j S t|t js$t|r,|| _nt |f|| _d| _dS )a  
        Set the connection style. Old attributes are forgotten.

        Parameters
        ----------
        connectionstyle : str or `.ConnectionStyle` or None, optional
            Can be a string with connectionstyle name with
            optional comma-separated attributes, e.g.::

                set_connectionstyle("arc,angleA=0,armA=30,rad=10")

            Alternatively, the attributes can be provided as keywords, e.g.::

                set_connectionstyle("arc", angleA=0,armA=30,rad=10)

            Without any arguments (or with ``connectionstyle=None``), return
            available styles as a list of strings.
        NT)r  r  rA   r  rO  
_connectorrl   )r2   rc  rk  r9   r9   r:   r_    s    z#FancyArrowPatch.set_connectionstylec             C   s   | j S )z"Return the `ConnectionStyle` used.)rj  )r2   r9   r9   r:   get_connectionstyle  s    z#FancyArrowPatch.get_connectionstylec             K   s<   |dkrt j S t|t jr$|| _nt |f|| _d| _dS )aH  
        Set the arrow style. Old attributes are forgotten. Without arguments
        (or with ``arrowstyle=None``) returns available box styles as a list of
        strings.

        Parameters
        ----------
        arrowstyle : None or ArrowStyle or str, default: None
            Can be a string with arrowstyle name with optional comma-separated
            attributes, e.g.::

                set_arrowstyle("Fancy,head_length=0.2")

            Alternatively attributes can be provided as keywords, e.g.::

                set_arrowstyle("fancy", head_length=0.2)

        NT)r  r  rA   r  _arrow_transmuterrl   )r2   rb  rk  r9   r9   r:   r`    s    zFancyArrowPatch.set_arrowstylec             C   s   | j S )zReturn the arrowstyle object.)rl  )r2   r9   r9   r:   get_arrowstyle  s    zFancyArrowPatch.get_arrowstylec             C   s   || _ d| _dS )zf
        Set the mutation scale.

        Parameters
        ----------
        scale : float
        TN)rJ  rl   )r2   r   r9   r9   r:   rP    s    z"FancyArrowPatch.set_mutation_scalec             C   s   | j S )z\
        Return the mutation scale.

        Returns
        -------
        scalar
        )rJ  )r2   r9   r9   r:   rQ    s    z"FancyArrowPatch.get_mutation_scalec             C   s   || _ d| _dS )zz
        Set the aspect ratio of the bbox mutation.

        Parameters
        ----------
        aspect : float
        TN)rK  rl   )r2   rR  r9   r9   r:   rS    s    z#FancyArrowPatch.set_mutation_aspectc             C   s   | j S )z-Return the aspect ratio of the bbox mutation.)rK  )r2   r9   r9   r:   rT    s    z#FancyArrowPatch.get_mutation_aspectc             C   s2   | j  \}}tj|r tj| }| j j j|S )z
        Return the path of the arrow in the data coordinates. Use
        get_path_in_displaycoord() method to retrieve the arrow path
        in display coordinates.
        )get_path_in_displaycoordrP   r  r   Zmake_compound_pathr;   rM  transform_path)r2   r   r  r9   r9   r:   r<     s    

zFancyArrowPatch.get_pathc             C   s   | j  }| jdk	rr| j| jd }| j| jd }| j j||f\}}| j ||| j| j| j| | j	| d}n| j j
| j}| j || j | | j | | j \}}||fS )z<Return the mutated path of the arrow in display coordinates.Nr   r   )r  r  r  r  )rf  rZ  r   r;   r   rk  r  r  r  r  ro  r\  rm  rQ  rC   rT  )r2   rd  r  r  r   r  r9   r9   r:   rn  %  s"    



z(FancyArrowPatch.get_path_in_displaycoordc             C   s   | j  sd S | j|x}| j|jd | j \}}tj|sJ|g}|g}tj }x6t	||D ](\}}||||r| j
d r| j
nd  q^W W d Q R X d S )Ng      ?r@   )r   r   ra  r   rn  rP   r  r	   rf   rO  r]   )r2   r   r   r>   r  r   r  r  r9   r9   r:   r   A  s    
zFancyArrowPatch.draw)NNNr]  r^  NNr  r  r   Nr   )N)r   r   r   r   rn   r   r   r   r   ra  rf  rg  rh  ri  r_  rk  r`  rm  rP  rQ  rS  rT  r<   rn  r   r9   r9   r9   r:   rV    s>             f

rV  c               @   sZ   e Zd ZdZdd ZejdddZdddZdd Z	dd Z
dd Zdd Zdd ZdS )ConnectionPatchz>A patch that connects two points (possibly in different axes).c             C   s(   d| j d | j d | jd | jd f S )Nz#ConnectionPatch((%g, %g), (%g, %g))r   r   )xy1xy2)r2   r9   r9   r:   r   [  s    zConnectionPatch.__str__Nr  r^                $@F      ?c             K   sf   |dkr|}|| _ || _|| _|| _|| _|| _tj| fdd|||	|
||||||d| d| _dS )a(  
        Connect point *xyA* in *coordsA* with point *xyB* in *coordsB*.

        Valid keys are

        ===============  ======================================================
        Key              Description
        ===============  ======================================================
        arrowstyle       the arrow style
        connectionstyle  the connection style
        relpos           default is (0.5, 0.5)
        patchA           default is bounding box of the text
        patchB           default is None
        shrinkA          default is 2 points
        shrinkB          default is 2 points
        mutation_scale   default is text size (in points)
        mutation_aspect  default is 1.
        ?                any key for `matplotlib.patches.PathPatch`
        ===============  ======================================================

        *coordsA* and *coordsB* are strings that indicate the
        coordinates of *xyA* and *xyB*.

        =================  ===================================================
        Property           Description
        =================  ===================================================
        'figure points'    points from the lower left corner of the figure
        'figure pixels'    pixels from the lower left corner of the figure
        'figure fraction'  0, 0 is lower left of figure and 1, 1 is upper right
        'axes points'      points from lower left corner of axes
        'axes pixels'      pixels from lower left corner of axes
        'axes fraction'    0, 0 is lower left of axes and 1, 1 is upper right
        'data'             use the coordinate system of the object being
                           annotated (default)
        'offset points'    offset (in points) from the *xy* value
        'polar'            you can specify *theta*, *r* for the annotation,
                           even in cartesian plots.  Note that if you are using
                           a polar axes, you do not need to specify polar for
                           the coordinate system since that is the native
                           "data" coordinate system.
        =================  ===================================================

        Alternatively they can be set to any valid
        `~matplotlib.transforms.Transform`.

        .. note::

           Using `ConnectionPatch` across two `~.axes.Axes` instances
           is not directly compatible with :doc:`constrained layout
           </tutorials/intermediate/constrainedlayout_guide>`. Add the artist
           directly to the `.Figure` instead of adding it to a specific Axes.

           .. code-block:: default

              fig, ax = plt.subplots(1, 2, constrained_layout=True)
              con = ConnectionPatch(..., axesA=ax[0], axesB=ax[1])
              fig.add_artist(con)

        Nr   r   )r  r  rb  rc  r  r  r  r  rM  rN  rT  rd  )r   r   )r   r   )	rq  rr  coords1coords2axesAaxesBrV  r   _annotation_clip)r2   ZxyAZxyBZcoordsAZcoordsBrx  ry  rb  rc  r  r  r  r  rM  rN  rT  rd  r8   r9   r9   r:   r   _  s,    IzConnectionPatch.__init__c             C   s  |}|dkr| j }tj|}|dkrB|| jjd 9 }|jdd}n |dkrT| jj}n|dkrb|j}|\}}|d	kr|j}t	| j
|}t	| j|}|j||fS |d
kr| jd
kr| j| jd	S | j| j| j|| jj d  S |dkr&|| }}	|	tj| }|	tj| }|j}|j||fS |dkr|| jj}
|dkrL|
j| n|
j| }|dkrj|
j| n|
j| }||fS |dkr|j}
|dkr|
j| n|
j| }|dkr|
j| n|
j| }||fS t|tjr|j|S t| ddS )z,Calculate the pixel position of given point.Nfigure pointsaxes pointsH   rZ   Zpixelszfigure fractionzaxes fractiondatazoffset pointsZpolarzfigure pixelsr   zaxes pixelsz) is not a valid coordinate transformation)r{  r|  )r;  rP   r&  figureZdpirf  ZtransFigureZ	transAxesZ	transDatarx   r   r   r   Zxycoords_get_xyr   r=  r>  r   r   r   r   r   rA   r	   Z	Transformr'  )r2   r   r   r;  s0rH   rI   r=   r@  r  Zbbr9   r9   r:   r    sR    







zConnectionPatch._get_xyc             C   s   || _ d| _dS )a  
        Set the clipping behavior.

        Parameters
        ----------
        b : bool or None

            - *False*: The annotation will always be drawn regardless of its
              position.
            - *True*: The annotation will only be drawn if ``self.xy`` is
              inside the axes.
            - *None*: The annotation will only be drawn if ``self.xy`` is
              inside the axes and  ``self.xycoords == "data"``.
        TN)rz  rl   )r2   r   r9   r9   r:   set_annotation_clip  s    z#ConnectionPatch.set_annotation_clipc             C   s   | j S )zx
        Return the clipping behavior.

        See `.set_annotation_clip` for the meaning of the return value.
        )rz  )r2   r9   r9   r:   get_annotation_clip  s    z#ConnectionPatch.get_annotation_clipc             C   s   | j  }| j| j| j| j}| j| j| j| j}| j ||| j	| j
| j| | j| d}| j || j | | j | | j \}}||fS )z<Return the mutated path of the arrow in display coordinates.)r  r  r  r  )rf  r  rq  rv  rx  rr  rw  ry  rk  r  r  r  r  rm  rQ  rC   rT  )r2   rd  r  r  r>   r  r9   r9   r:   rn    s    

z(ConnectionPatch.get_path_in_displaycoordc             C   s   | j  }|s|dkrX| jdkrX| j| j| j| j}| jdkrD| j}n| j}|j|sXdS |sn|dkr| jdkr| j| j| j| j	}| j	dkr| j}n| j	}|j|sdS dS )z/Check whether the annotation needs to be drawn.Nr~  FT)
r  rv  r  rq  rx  r;  rG   rw  rr  ry  )r2   r   r   Zxy_pixelr;  r9   r9   r:   	_check_xy!  s     



zConnectionPatch._check_xyc             C   s8   |d k	r|| _ | j  s$| j| r(d S tj| | d S )N)Z	_rendererr   r  rV  r   )r2   r   r9   r9   r:   r   :  s
    zConnectionPatch.draw)NNNr  r^  NNrs  rs  rt  NFru  )N)r   r   r   r   r   r   r   r   r  r  r  rn  r  r   r9   r9   r9   r:   rp  X  s*              Y
1rp  )r   r   r   r   r   r   r   r   r   r   r   r   )NT)rX  N)N)Er   r   rv  r  numbersr   r  numpyrP   Z
matplotlibr   r`  r   r   r   r   r   ry   r	   Zbezierr
   r   r   r   r   r   r   r   r>   r   Z_define_aliasesr   r   ZkwdocZpatchdocrX  Zinterpdr1   r   r   r   r   r   r   r   r   r   r   r\  getdoc
splitlinesr   r   r   r   rW  rY  r]  r^  r  r  r  r  r  r  rh  r   rV  rp  r9   r9   r9   r:   <module>   s    (
    I
 Q :Z^Z9e" ) n

	D   V   +     j


  
  f