3
6Ad]ÕQ ã               @   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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dMD ]Z%ej&j'e%e$iƒ qâW 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"ƒZ0G d$d„ de.ƒZ1ej&j'de1j)j2iƒ ej3d%d&d'�G d(d„ de"ƒƒZ4G d)d„ de,ƒZ5G d*d„ de"ƒZ6G d+d„ de6ƒZ7G d,d„ de6ƒZ8dNd.d/„Z9dOd1d2„Z:dPd4d5„Z;d6d7„ Z<d8d9„ Z=G d:d;„ d;e>ƒZ?dQdd<œd=d>„Z@G d?d@„ d@e?ƒZAej&j'e<eAjBƒe=eAjBƒdA� G dBd„ de"ƒZCG dCdD„ dDe?ƒZDdEdF„ ZEG dGdH„ dHe?ƒZFej&j'e<eFjBƒe<eDjBƒdI� G dJd&„ d&e"ƒZGG dKdL„ dLeGƒZHdS )Ré    N)ÚNumberé   )ÚartistÚcbookÚcolorsÚ	docstringÚlinesÚ
transforms)
ÚNonIntersectingPathExceptionÚconcatenate_pathsÚget_cos_sinÚget_intersectionÚget_parallelsÚinside_circleÚmake_path_regularÚmake_wedged_bezier2Ú)split_bezier_intersecting_with_closedpathÚsplit_path_inout)ÚPathÚaaÚecÚfcÚlsÚlw)ÚantialiasedÚ	edgecolorÚ	facecolorÚ	linestyleÚ	linewidthc            
   @   sp  e Zd ZdZdZdWZdXZdZdYdd„Zdd„ Z	dd„ Z
dZdd„Zd[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'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;d<„ Z d=d>„ Z!d?d@„ Z"e#e"e!ƒZ$dAdB„ Z%dCdD„ Z&dEdF„ Z'dGdH„ Z(dIdJ„ Z)dKdL„ Z*e+j,dMdN„ ƒZ-e.j/dOdP„ ƒZ0dQdR„ Z1d]dSdT„Z2dUdV„ Z3d	S )^Ú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   ÚbuttÚroundÚ
projectingÚmiterÚbevelFNTc             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	rŽt	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Úsolidr    r#   z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   Ú_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© rC   ú}/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.6/site-packages/matplotlib-3.1.1-py3.6-linux-x86_64.egg/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 :meth:`get_path`.
        r   )Úget_transformÚget_pathÚto_polygonsr:   )r<   ÚtransÚpathZpolygonsrC   rC   rD   Ú	get_vertsb   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   )Ú
isinstanceÚ_pickerr   Úget_edgecolorÚget_linewidth)r<   ÚradiusÚ_radiusrC   rC   rD   Ú_process_radiusq   s    zPatch._process_radiusc                s¤   ˆj dk	rˆj ˆˆ ƒS ˆjˆƒ‰ˆjƒ j}|dk	rxˆ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ÚyrE   )Ú.0Úsubpath)Ú
mouseeventrP   r<   rC   rD   ú	<genexpr>•   s   z!Patch.contains.<locals>.<genexpr>)Ú	_containsrR   rF   ÚcodesÚverticesÚnpÚwherer   ÚMOVETOÚmapÚsplitÚany)r<   rX   rP   r[   r\   ÚidxsZsubpathsÚinsiderC   )rX   rP   r<   rD   Úcontains}   s    





zPatch.containsc             C   s    | j |ƒ}| jƒ j|| jƒ |ƒS )zÇ
        Returns ``True`` if the given *point* is inside the path
        (transformed with its transform attribute).

        *radius* allows the path to be made slightly larger or smaller.
        )rR   rF   rS   rE   )r<   ÚpointrP   rC   rC   rD   rS   š   s    

zPatch.contains_pointc             C   s    | j |ƒ}| jƒ j|| jƒ |ƒS )a  
        Returns a bool array which is ``True`` if the (closed) path
        contains the corresponding point.
        (transformed with its transform attribute).

        *points* must be Nx2 array.
        *radius* allows the path to be made slightly larger or smaller.
        )rR   rF   Úcontains_pointsrE   )r<   ÚpointsrP   rC   rC   rD   rg   ¦   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 )zM
        Updates this :class:`Patch` from the properties of *other*.
        N)r   r&   Úupdate_fromÚ
_edgecolorÚ
_facecolorÚ_original_edgecolorÚ_original_facecolorr,   Ú_hatchr+   r1   r5   r2   Úset_transformÚget_data_transformÚis_transform_setÚ_transformSet)r<   ÚotherrC   rC   rD   ri   ´   s    zPatch.update_fromc             C   s   | j ƒ j| jƒ ƒS )z‡
        Return a :class:`~matplotlib.transforms.Bbox` object defining
        the axis-aligned extents of the :class:`Patch`.
        )rF   Úget_extentsrE   )r<   rC   rC   rD   rt   Ê   s    zPatch.get_extentsc             C   s   | j ƒ tjj| ƒ S )zm
        Return the :class:`~matplotlib.transforms.Transform` applied
        to the :class:`Patch`.
        )Úget_patch_transformr   r&   rE   )r<   rC   rC   rD   rE   Ñ   s    zPatch.get_transformc             C   s   t jj| ƒS )zŒ
        Return the :class:`~matplotlib.transforms.Transform` instance which
        maps data coordinates to physical coordinates.
        )r   r&   rE   )r<   rC   rC   rD   rp   Ø   s    zPatch.get_data_transformc             C   s   t jƒ S )ah  
        Return the :class:`~matplotlib.transforms.Transform` instance which
        takes 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)r<   rC   rC   rD   ru   ß   s    	zPatch.get_patch_transformc             C   s   | j S )zV
        Returns True if the :class:`Patch` is to be drawn with antialiasing.
        )Ú_antialiased)r<   rC   rC   rD   Úget_antialiasedê   s    zPatch.get_antialiasedc             C   s   | j S )z>
        Return the edge color of the :class:`Patch`.
        )rj   )r<   rC   rC   rD   rN   ð   s    zPatch.get_edgecolorc             C   s   | j S )z>
        Return the face color of the :class:`Patch`.
        )rk   )r<   rC   rC   rD   Úget_facecolorö   s    zPatch.get_facecolorc             C   s   | j S )z2
        Return the line width in points.
        )r2   )r<   rC   rC   rD   rO   ü   s    zPatch.get_linewidthc             C   s   | j S )z'
        Return the linestyle.
        )Ú
_linestyle)r<   rC   rC   rD   Ú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)   rw   Ústale)r<   r   rC   rC   rD   r6     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*   Ú_alpharj   r+   r|   )r<   r=   Úset_hatch_colorrC   rC   rD   Ú_set_edgecolor  s    
zPatch._set_edgecolorc             C   s   || _ | j|ƒ dS )zz
        Set the patch edge color.

        Parameters
        ----------
        color : color or None or 'auto'
        N)rl   r�   )r<   r=   rC   rC   rD   r/   $  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,   r   r   r*   rk   r|   )r<   r=   ÚalpharC   rC   rD   Ú_set_facecolor/  s
    
zPatch._set_facecolorc             C   s   || _ | j|ƒ dS )zp
        Set the patch face color.

        Parameters
        ----------
        color : color or None
        N)rm   rƒ   )r<   r=   rC   rC   rD   r0   6  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)r0   r/   )r<   ÚcrC   rC   rD   r.   A  s    
zPatch.set_colorc             C   s\   |dk	r2yt |ƒ W n tk
r0   tdƒ‚Y nX tjj| |ƒ | j| jƒ | j| jƒ dS )z
        Set the alpha transparency of the patch.

        Parameters
        ----------
        alpha : float or None
        Nzalpha must be a float or None)	ÚfloatÚ	TypeErrorr   r&   Ú	set_alpharƒ   rm   r�   rl   )r<   r‚   rC   rC   rD   r‡   Q  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)   r…   r2   r1   ÚmlinesÚ_scale_dashesÚ_dashoffsetÚ_dashesr|   )r<   ÚwÚoffsetr   rC   rC   rD   r5   c  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)	rz   rˆ   Ú_get_dash_patternr1   r‰   r2   rŠ   r‹   r|   )r<   r   r�   rC   rC   rD   r4   w  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,   rƒ   rm   r�   rl   r|   )r<   ÚbrC   rC   rD   r3   ™  s    
zPatch.set_fillc             C   s   | j S )zreturn whether fill is set)r,   )r<   rC   rC   rD   Úget_fill¦  s    zPatch.get_fillc             C   s<   |j ƒ }|| jkr,td|f d| jf  ƒ‚|| _d| _dS )z{
        Set the patch capstyle

        Parameters
        ----------
        s : {'butt', 'round', 'projecting'}
        zset_capstyle passed "%s";
zvalid capstyles are %sTN)ÚlowerÚvalidCapÚ
ValueErrorÚ	_capstyler|   )r<   ÚsrC   rC   rD   r8   ¯  s    

zPatch.set_capstylec             C   s   | j S )zReturn the current capstyle)r•   )r<   rC   rC   rD   Úget_capstyle¾  s    zPatch.get_capstylec             C   s<   |j ƒ }|| jkr,td|f d| jf  ƒ‚|| _d| _dS )zx
        Set the patch joinstyle

        Parameters
        ----------
        s : {'miter', 'round', 'bevel'}
        zset_joinstyle passed "%s";
zvalid joinstyles are %sTN)r’   Ú	validJoinr”   Ú
_joinstyler|   )r<   r–   rC   rC   rD   r9   Â  s    

zPatch.set_joinstylec             C   s   | j S )zReturn the current joinstyle)r™   )r<   rC   rC   rD   Ú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)rn   r|   )r<   r>   rC   rC   rD   r7   Õ  s    zPatch.set_hatchc             C   s   | j S )z#Return the current hatching pattern)rn   )r<   rC   rC   rD   Ú	get_hatchô  s    zPatch.get_hatchc             c   s`  |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ƒ y|j| jƒ W n" tk
rò   tjddd� Y nX | jƒ d	k	�r|j| jƒ Ž  | j ƒ �r4d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)ÚisRGBArK   r   z3.1zoYour backend does not support setting the hatch color; such backends will become unsupported in Matplotlib 3.3.)ÚmessageN)ÚPathEffectRendererF))Ú
open_groupÚget_gidÚnew_gcÚset_foregroundrj   r2   r5   Ú
set_dashesrŠ   r‹   r8   r•   r9   r™   r6   rw   Ú_set_gc_clipÚset_urlÚ_urlÚset_snapÚget_snapr‡   r   rn   r7   r€   r+   ÚAttributeErrorr   Úwarn_deprecatedÚget_sketch_paramsÚset_sketch_paramsÚget_path_effectsÚmatplotlib.patheffectsrŸ   Ú	functoolsÚpartialÚ	draw_pathÚrestoreÚclose_groupr|   )r<   ÚrendererÚgcr   rŸ   rC   rC   rD   Ú_bind_draw_path_functionø  s>    



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 )z0Draw the :class:`Patch` to the given *renderer*.Nr   )rŠ   rK   )	Úget_visibler   Ú_setattr_cmr·   rF   rE   Útransform_path_non_affineÚ
get_affinerk   )r<   rµ   r²   rI   Ú	transformÚtpathÚaffinerC   rC   rD   Údraw3  s    
z
Patch.drawc             C   s   t dƒ‚dS )z/
        Return the path of this patch
        zDerived must overrideN)ÚNotImplementedError)r<   rC   rC   rD   rF   F  s    zPatch.get_pathc             C   s   | j ƒ j| jƒ ƒS )N)rF   rt   rE   )r<   rµ   rC   rC   rD   Úget_window_extentL  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)r<   ÚxyrT   rU   rC   rC   rD   Ú_convert_xy_unitsO  s    zPatch._convert_xy_units)r    r!   r"   )r#   r!   r$   )
NNNNNNNTNN)N)N)N)N)4Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úzorderr“   r˜   r~   r'   rJ   rR   re   rS   rg   ri   rt   rE   rp   ru   rx   rN   ry   rO   r{   r6   r�   r/   rƒ   r0   r.   r‡   r5   r4   r3   r‘   Úpropertyr?   r8   r—   r9   rš   r7   r›   Ú
contextlibÚcontextmanagerr·   r   Úallow_rasterizationr¿   rF   rÁ   rÅ   rC   rC   rC   rD   r      sj            
.


"
;
r   Ú	RectangleÚCircleÚRegularPolygonÚPolygonÚWedgeÚArrowÚ
FancyArrowÚYAArrowÚCirclePolygonÚEllipseÚArcÚFancyBboxPatchc               @   sl   e 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S )ÚShadowc             C   s   dt | jƒ S )Nz
Shadow(%s))Ústrrœ   )r<   rC   rC   rD   Ú__str__c  s    zShadow.__str__Nc             K   s:   t j| ƒ || _|| _|| | _| _tjƒ | _| j	ƒ  dS )a  
        Create a shadow of the given *patch* offset by *ox*, *oy*.
        *props*, if not *None*, is a patch property update dictionary.
        If *None*, the shadow will have have the same color as the face,
        but darkened.

        kwargs are
        %(Patch)s
        N)
r   r'   rœ   ÚpropsÚ_oxÚ_oyr	   ÚAffine2DÚ_shadow_transformÚ_update)r<   rœ   ÚoxÚoyrÞ   rB   rC   rC   rD   r'   f  s    

zShadow.__init__c             C   sz   | j | jƒ | jtj| jjtj ƒƒ | jd k	r>| j| jƒ n8dtj	t
j| jjƒ ƒƒ }| j|ƒ | j|ƒ | jdƒ d S )Ng333333Ó?g      à?)ri   rœ   Ú
set_zorderr]   Ú	nextafterrÊ   ÚinfrÞ   r;   Úasarrayr   Úto_rgbry   r0   r/   r‡   )r<   r=   rC   rC   rD   rã   x  s    


zShadow._updatec             C   s.   |j | jƒ}|j | jƒ}| jjƒ j||ƒ d S )N)Úpoints_to_pixelsrß   rà   râ   ÚclearÚ	translate)r<   rµ   rä   rå   rC   rC   rD   Ú_update_transform†  s    zShadow._update_transformc             C   s   | j S )N)rß   )r<   rC   rC   rD   Ú_get_ox‹  s    zShadow._get_oxc             C   s
   || _ d S )N)rß   )r<   rä   rC   rC   rD   Ú_set_oxŽ  s    zShadow._set_oxc             C   s   | j S )N)rà   )r<   rC   rC   rD   Ú_get_oy‘  s    zShadow._get_oyc             C   s
   || _ d S )N)rà   )r<   rå   rC   rC   rD   Ú_set_oy”  s    zShadow._set_oyc             C   s
   | j jƒ S )N)rœ   rF   )r<   rC   rC   rD   rF   —  s    zShadow.get_pathc             C   s   | j jƒ | j S )N)rœ   ru   râ   )r<   rC   rC   rD   ru   š  s    zShadow.get_patch_transformc             C   s   | j |ƒ tj| |ƒ d S )N)rî   r   r¿   )r<   rµ   rC   rC   rD   r¿   �  s    
zShadow.draw)N)rÆ   rÇ   rÈ   rÝ   r   Údedent_interpdr'   rã   rî   rï   rð   rñ   rò   rF   ru   r¿   rC   rC   rC   rD   rÛ   b  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Ï   zu
    A rectangle with lower left at *xy* = (*x*, *y*) with
    specified *width*, *height* and rotation *angle*.
    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)r<   ÚparsÚfmtrC   rC   rD   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 bottom and left rectangle coordinates
        width : float
            Rectangle width
        height : float
            Rectangle height
        angle : float, optional
          rotation in degrees anti-clockwise about *xy* (default is 0.0)
        fill : bool, optional
            Whether to fill the rectangle (default is ``True``)

        Notes
        -----
        Valid kwargs are:
        %(Patch)s
        r   r   N)r   r'   rô   rõ   rö   r÷   Ú_x1Ú_y1r…   rø   r	   rv   Ú_rect_transform)r<   rÄ   ÚwidthÚheightrø   rB   rC   rC   rD   r'   ­  s    


zRectangle.__init__c             C   s   t jƒ S )z7
        Return the vertices of the rectangle.
        )r   Úunit_rectangle)r<   rC   rC   rD   rF   Ò  s    zRectangle.get_pathc             C   sX   | j ƒ \}}}}tjj||||ƒ}tjƒ }|j||| jƒ tj|ƒ| _|  j|7  _dS )a  NOTE: 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á   Úrotate_deg_aroundrø   ÚBboxTransformTorþ   )r<   Úx0Úy0Úx1Úy1ÚbboxZ	rot_transrC   rC   rD   Ú_update_patch_transformØ  s    z!Rectangle._update_patch_transformc             C   s   | j | j | _d S )N)rô   rö   rü   )r<   rC   rC   rD   Ú
_update_x1å  s    zRectangle._update_x1c             C   s   | j | j | _d S )N)rõ   r÷   rý   )r<   rC   rC   rD   Ú
_update_y1è  s    zRectangle._update_y1c             C   s<   | j | jƒ}| j| jƒ}| j | jƒ}| j| jƒ}||||fS )z2
        Convert bounds of the rectangle.
        )rÂ   rô   rÃ   rõ   rü   rý   )r<   r  r  r	  r
  rC   rC   rD   r  ë  s
    zRectangle._convert_unitsc             C   s   | j ƒ  | jS )N)r  rþ   )r<   rC   rC   rD   ru   õ  s    zRectangle.get_patch_transformc             C   s   | j S )z'Return the left coord of the rectangle.)rô   )r<   rC   rC   rD   Úget_xù  s    zRectangle.get_xc             C   s   | j S )z)Return the bottom coord of the rectangle.)rõ   )r<   rC   rC   rD   Úget_yý  s    zRectangle.get_yc             C   s   | j | jfS )z3Return the left and bottom coords of the rectangle.)rô   rõ   )r<   rC   rC   rD   Úget_xy  s    zRectangle.get_xyc             C   s   | j S )z"Return the width of the rectangle.)rö   )r<   rC   rC   rD   Ú	get_width  s    zRectangle.get_widthc             C   s   | j S )z#Return the height of the rectangle.)r÷   )r<   rC   rC   rD   Ú
get_height	  s    zRectangle.get_heightc             C   s   || _ | jƒ  d| _dS )z$Set the left coord of the rectangle.TN)rô   r  r|   )r<   rT   rC   rC   rD   Úset_x  s    zRectangle.set_xc             C   s   || _ | jƒ  d| _dS )z&Set the bottom coord of the rectangle.TN)rõ   r  r|   )r<   rU   rC   rC   rD   Úset_y  s    zRectangle.set_yc             C   s&   |\| _ | _| jƒ  | jƒ  d| _dS )z…
        Set the left and bottom coords of the rectangle.

        Parameters
        ----------
        xy : (float, float)
        TN)rô   rõ   r  r  r|   )r<   rÄ   rC   rC   rD   Úset_xy  s    zRectangle.set_xyc             C   s   || _ | jƒ  d| _dS )zSet the width of the rectangle.TN)rö   r  r|   )r<   rŒ   rC   rC   rD   Ú	set_width&  s    zRectangle.set_widthc             C   s   || _ | jƒ  d| _dS )z Set the height of the rectangle.TN)r÷   r  r|   )r<   ÚhrC   rC   rD   Ú
set_height,  s    zRectangle.set_heightc             G   s\   t |ƒdkr|d \}}}}n|\}}}}|| _|| _|| _|| _| jƒ  | jƒ  d| _dS )zj
        Set the bounds of the rectangle: l,b,w,h

        ACCEPTS: (left, bottom, width, height)
        r   r   TN)r:   rô   rõ   rö   r÷   r  r  r|   )r<   ÚargsÚlr�   rŒ   r  rC   rC   rD   Ú
set_bounds2  s    zRectangle.set_boundsc             C   s"   | j ƒ \}}}}tjj||||ƒS )N)r  r	   r  r  )r<   r  r  r	  r
  rC   rC   rD   Úget_bboxD  s    zRectangle.get_bboxN)rû   )rÆ   rÇ   rÈ   rÉ   rÝ   r   ró   r'   rF   r  r  r  r  ru   r  r  r  r  r  r  r  r  r  r  r  r  rË   rÄ   rC   rC   rC   rD   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Ú_numVerticesrQ   Ú_orientation)r<   r–   rC   rC   rD   rÝ   O  s    zRegularPolygon.__str__é   r   c             K   sH   || _ || _|| _|| _tj|ƒ| _tjƒ | _	| j
ƒ  tj| f|Ž dS )af  
        Constructor arguments:

        *xy*
          A length 2 tuple (*x*, *y*) of the center.

        *numVertices*
          the number of vertices.

        *radius*
          The distance from the center to each of the vertices.

        *orientation*
          rotates the polygon (in radians).

        Valid kwargs are:
        %(Patch)s
        N)r  r  r   rQ   r   Úunit_regular_polygonÚ_pathr	   rá   Ú_poly_transformrî   r   r'   )r<   rÄ   ÚnumVerticesrP   ÚorientationrB   rC   rC   rD   r'   T  s    
zRegularPolygon.__init__c             C   s&   | j jƒ j| jƒj| jƒj| jŽ  d S )N)r$  rì   ÚscalerP   Úrotater&  rí   rÄ   )r<   rC   rC   rD   rî   s  s    
z RegularPolygon._update_transformc             C   s   | j S )N)r  )r<   rC   rC   rD   rÄ   y  s    zRegularPolygon.xyc             C   s   || _ | jƒ  d S )N)r  rî   )r<   rÄ   rC   rC   rD   rÄ   }  s    c             C   s   | j S )N)r   )r<   rC   rC   rD   r&  ‚  s    zRegularPolygon.orientationc             C   s   || _ | jƒ  d S )N)r   rî   )r<   r&  rC   rC   rD   r&  †  s    c             C   s   | j S )N)rQ   )r<   rC   rC   rD   rP   ‹  s    zRegularPolygon.radiusc             C   s   || _ | jƒ  d S )N)rQ   rî   )r<   rP   rC   rC   rD   rP   �  s    c             C   s   | j S )N)r  )r<   rC   rC   rD   Únumvertices”  s    zRegularPolygon.numverticesc             C   s
   || _ d S )N)r  )r<   r%  rC   rC   rD   r)  ˜  s    c             C   s   | j S )N)r#  )r<   rC   rC   rD   rF   œ  s    zRegularPolygon.get_pathc             C   s   | j ƒ  | jS )N)rî   r$  )r<   rC   rC   rD   ru   Ÿ  s    z"RegularPolygon.get_patch_transformN)r!  r   )rÆ   rÇ   rÈ   rÉ   rÝ   r   ró   r'   rî   rË   rÄ   Úsetterr&  rP   r)  rF   ru   rC   rC   rC   rD   rÑ   K  s   c               @   s2   e Zd ZdZdZdd„ Zej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   )r:   r#  r\   Útuple)r<   r–   rC   rC   rD   rÝ   ª  s    zPathPatch.__str__c             K   s   t j| f|Ž || _dS )zp
        *path* is a :class:`matplotlib.path.Path` object.

        Valid kwargs are:
        %(Patch)s
        N)r   r'   r#  )r<   rI   rB   rC   rC   rD   r'   ®  s    zPathPatch.__init__c             C   s   | j S )N)r#  )r<   rC   rC   rD   rF   ¹  s    zPathPatch.get_pathN)
rÆ   rÇ   rÈ   rÉ   r~   rÝ   r   ró   r'   rF   rC   rC   rC   rD   r+  ¤  s
   r+  c               @   sf   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Ze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   )r:   r#  r\   r,  )r<   r–   rC   rC   rD   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 kwargs are:
        %(Patch)s
        N)r   r'   Ú_closedr  )r<   rÄ   ÚclosedrB   rC   rC   rD   r'   Å  s    zPolygon.__init__c             C   s   | j S )z²
        Get the path of the polygon

        Returns
        -------
        path : Path
           The :class:`~matplotlib.path.Path` object for
           the polygon
        )r#  )r<   rC   rC   rD   rF   Ô  s    
zPolygon.get_pathc             C   s   | j S )z‹
        Returns if the polygon is closed

        Returns
        -------
        closed : bool
            If the path is closed
        )r-  )r<   rC   rC   rD   Ú
get_closedà  s    	zPolygon.get_closedc             C   s4   | j t|ƒkrdS t|ƒ| _ | j| jƒ ƒ d| _dS )z”
        Set if the polygon is closed

        Parameters
        ----------
        closed : bool
           True if the polygon is closed
        NT)r-  r�   r  r  r|   )r<   r.  rC   rC   rD   Ú
set_closedë  s
    	
zPolygon.set_closedc             C   s   | j jS )z£
        Get the vertices of the path.

        Returns
        -------
        vertices : (N, 2) numpy array
            The coordinates of the vertices.
        )r#  r\   )r<   rC   rC   rD   r  ú  s    	zPolygon.get_xyc             C   sˆ   t j|ƒ}| jrBt|ƒrn|d |d kjƒ rnt j||d ggƒ}n,t|ƒdkrn|d |d kjƒ rn|dd	… }t|| jd�| _d| _	dS )
z¥
        Set the vertices of the polygon.

        Parameters
        ----------
        xy : (N, 2) array-like
            The coordinates of the vertices.
        r   r   é   N)r.  Téÿÿÿÿr2  r2  )
r]   ré   r-  r:   rb   ÚconcatenateÚallr   r#  r|   )r<   rÄ   rC   rC   rD   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'   rF   r/  r0  r  r  Ú_get_xyZ_set_xyrË   rÄ   rC   rC   rC   rD   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ÿ   )r<   rù   rú   rC   rC   rD   rÝ   "  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 kwargs are:

        %(Patch)s
        N)r   r'   r7  r8  rÿ   r9  r:  r	   rv   Ú_patch_transformÚ_recompute_path)r<   r7  r8  r9  r:  rÿ   rB   rC   rC   rD   r'   (  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 )
Néh  gê-�™—q=r   r   )r   r=  r2  )r   r   )r   r   )r   r   )Úabsr:  r9  r   r_   ÚLINETOÚarcrÿ   r\   r8  r]   ÚvstackÚhstackr[   Ú	CLOSEPOLYr:   ré   r7  r#  )	r<   r9  r:  Ú	connectorr@  Úv1Úv2Úvr„   rC   rC   rD   r<  ;  s"    
"$
zWedge._recompute_pathc             C   s   d | _ || _d| _d S )NT)r#  r7  r|   )r<   r7  rC   rC   rD   Ú
set_centerY  s    zWedge.set_centerc             C   s   d | _ || _d| _d S )NT)r#  r8  r|   )r<   rP   rC   rC   rD   Ú
set_radius^  s    zWedge.set_radiusc             C   s   d | _ || _d| _d S )NT)r#  r9  r|   )r<   r9  rC   rC   rD   Ú
set_theta1c  s    zWedge.set_theta1c             C   s   d | _ || _d| _d S )NT)r#  r:  r|   )r<   r:  rC   rC   rD   Ú
set_theta2h  s    zWedge.set_theta2c             C   s   d | _ || _d| _d S )NT)r#  rÿ   r|   )r<   rÿ   rC   rC   rD   r  m  s    zWedge.set_widthc             C   s   | j d kr| jƒ  | j S )N)r#  r<  )r<   rC   rC   rD   rF   r  s    
zWedge.get_path)N)rÆ   rÇ   rÈ   rÉ   rÝ   r   ró   r'   r<  rH  rI  rJ  rK  r  rF   rC   rC   rC   rD   rÓ     s   c            
   @   st   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dd„ƒZ	dd„ Z
dd„ ZdS )rÔ   z
    An arrow patch.
    c             C   s   dS )NzArrow()rC   )r<   rC   rC   rD   rÝ   }  s    zArrow.__str__g        gš™™™™™¹?gš™™™™™é?g333333Ó?ç      ð?T)r.  c             K   sŽ   t j| f|Ž tj||ƒ}|dkr4|| }|| }	nd\}}	tjƒ j||ƒ}
tjj||	|	 |ddƒ}tjƒ j||ƒ}|
| | }|j	ƒ | _
dS )aˆ  
        Draws an arrow from (*x*, *y*) to (*x* + *dx*, *y* + *dy*).
        The width of the arrow is scaled by *width*.

        Parameters
        ----------
        x : scalar
            x coordinate of the arrow tail
        y : scalar
            y coordinate of the arrow tail
        dx : scalar
            Arrow length in the x direction
        dy : scalar
            Arrow length in the y direction
        width : scalar, optional (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 :class:`~matplotlib.patches.Patch`
            properties:

            %(Patch)s

        See Also
        --------
        :class:`FancyArrow` :
            Patch that allows independent control of the head and tail
            properties
        r   r   g        N)r   r   )r   r'   r]   Úhypotr	   rá   r'  Úfrom_valuesrí   Úfrozenr;  )r<   rT   rU   ÚdxÚdyrÿ   rB   ÚLÚcxÚsxZtrans1Ztrans2Ztrans3rH   rC   rC   rD   r'   †  s    
zArrow.__init__c             C   s   | j S )N)r#  )r<   rC   rC   rD   rF   µ  s    zArrow.get_pathc             C   s   | j S )N)r;  )r<   rC   rC   rD   ru   ¸  s    zArrow.get_patch_transformNgš™™™™™¹¿gš™™™™™¹¿g333333Ó¿)rL  )rÆ   rÇ   rÈ   rÉ   rÝ   r   r#  r   ró   r'   rF   ru   rC   rC   rC   rD   rÔ   y  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()rC   )r<   rC   rC   rD   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ê  
        Constructor arguments
          *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.

        Other valid kwargs (inherited from :class:`Patch`) are:
        %(Patch)s

        NrK   g      ø?r   r1  g        r   ÚleftÚrightrV  zGot unknown shape: %sr.  Tr2  r2  éþÿÿÿr2  )r   r   )	r]   rM  ÚemptyÚarrayr3  r”   ÚdotÚsuperr'   )r<   rT   rU   rP  rQ  rÿ   Zlength_includes_headÚ
head_widthÚhead_lengthÚshapeZoverhangZhead_starts_at_zerorB   ÚdistanceÚlengthÚvertsZhwZhlÚhsr   Zleft_half_arrowÚcoordsZright_half_arrowrS  rT  ÚM)Ú	__class__rC   rD   r'   Æ  sJ    !



zFancyArrow.__init__)rU  FNNrV  r   F)
rÆ   rÇ   rÈ   rÉ   r~   rÝ   r   ró   r'   Ú__classcell__rC   rC   )rg  rD   rÕ   ¼  s     z3.0ÚFancyArrowPatch)Úalternativec               @   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S )rÖ   z“
    Yet another arrow class.

    This is an arrow that is defined in display space and has a tip at
    *x1*, *y1* and a base at *x2*, *y2*.
    c             C   s   dS )Nz	YAArrow()rC   )r<   rC   rC   rD   rÝ   *  s    zYAArrow.__str__é   çš™™™™™¹?é   c             K   s6   || _ || _|| _|| _|| _tj| f|Ž || _dS )a	  
        Constructor arguments:

        *xytip*
          (*x*, *y*) location of arrow tip

        *xybase*
          (*x*, *y*) location the arrow base mid point

        *figure*
          The `Figure` instance (used to get the dpi setting).

        *width*
          The width of the arrow in points

        *frac*
          The fraction of the arrow length occupied by the head

        *headwidth*
          The width of the base of the arrow head in points

        Valid kwargs are:
        %(Patch)s

        N)ÚxytipÚxybaserÿ   ÚfracÚ	headwidthr   r'   Úfigure)r<   rr  rn  ro  rÿ   rp  rq  rB   rC   rC   rD   r'   -  s    zYAArrow.__init__c          	   C   sü   | j \}}| j\}}| j| jj d d }| j| jj d d }| j|||||ƒ\}}}	}
|| j||   }|| j||   }| j|||||ƒ\}}}}| j|||||ƒ\}}}}| j||	||||||gƒ}| j	||
||||||gƒ}t
tj||gƒdd�S )Ng      R@g       @T)r.  )rn  ro  rÿ   rr  Údpirq  Ú	getpointsrp  rÂ   rÃ   r   r]   Úcolumn_stack)r<   r	  r
  Úx2Úy2Úk1Úk2Zxb1Zyb1Zxb2Zyb2ÚxmÚymZxc1Zyc1Zxc2Zyc2Zxd1Zyd1Zxd2Zyd2ÚxsÚysrC   rC   rD   rF   S  s    

zYAArrow.get_pathc             C   s   t jƒ S )N)r	   rv   )r<   rC   rC   rD   ru   i  s    zYAArrow.get_patch_transformc             C   s"  t t|||||fƒ\}}}}}|| dkr>||| ||| fS || dkr^|| ||| |fS || ||  }d| }d}d| }	|d |d |d  d|d    }
|	 tj|	d d| |
  ƒ d|  }|| | | }|	 tj|	d d| |
  ƒ d|  }|| | | }||||fS )	a  
        For line segment defined by (*x1*, *y1*) and (*x2*, *y2*)
        return the points on the line that is perpendicular to the
        line and intersects (*x2*, *y2*) and the distance from (*x2*,
        *y2*) of the returned points is *k*.
        r   g      ð?r   r1  g       @rk  g      ð¿rY  )r`   r…   ÚmathÚsqrt)r<   r	  r
  rv  rw  ÚkÚmÚpmÚar�   r„   Zy3aZx3aZy3bZx3brC   rC   rD   rt  l  s    $((zYAArrow.getpointsN)rk  rl  rm  )rÆ   rÇ   rÈ   rÉ   rÝ   r   ró   r'   rF   ru   rt  rC   rC   rC   rD   rÖ   "  s   $c               @   s(   e Zd ZdZdd„ Zejd	dd„ƒZdS )
r×   z4
    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  rQ   r  )r<   r–   rC   rC   rD   rÝ   Œ  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 :class:`~matplotlib.patches.Circle`.

        Valid kwargs are:
        %(Patch)s

        r&  r   N)rÑ   r'   )r<   rÄ   rP   Ú
resolutionrB   rC   rC   rD   r'   �  s
    zCirclePolygon.__init__N)r!  r„  )rÆ   rÇ   rÈ   rÉ   rÝ   r   ró   r'   rC   rC   rC   rD   r×   ˆ  s
    c               @   sZ   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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ø   )r<   rù   rú   rC   rC   rD   rÝ   ©  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 : scalar, optional
            Rotation in degrees anti-clockwise.

        Notes
        -----
        Valid keyword arguments are
        %(Patch)s
        N)r   r'   r†  rÿ   r   rø   r   Úunit_circler#  r	   rv   r;  )r<   rÄ   rÿ   r   rø   rB   rC   rC   rD   r'   ¯  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  NOTE: 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Â   r†  rÃ   rÿ   r   r	   rá   r'  Ú
rotate_degrø   rí   r;  )r<   r7  rÿ   r   rC   rC   rD   Ú_recompute_transformË  s    zEllipse._recompute_transformc             C   s   | j S )z6
        Return the vertices of the rectangle
        )r#  )r<   rC   rC   rD   rF   Ú  s    zEllipse.get_pathc             C   s   | j ƒ  | jS )N)r‰  r;  )r<   rC   rC   rD   ru   à  s    zEllipse.get_patch_transformc             C   s   || _ d| _dS )zs
        Set the center of the ellipse.

        Parameters
        ----------
        xy : (float, float)
        TN)r†  r|   )r<   rÄ   rC   rC   rD   rH  ä  s    zEllipse.set_centerc             C   s   | j S )z2
        Return the center of the ellipse
        )r†  )r<   rC   rC   rD   Ú
get_centerï  s    zEllipse.get_centerN)r   )rÆ   rÇ   rÈ   rÉ   rÝ   r   ró   r'   r‰  rF   ru   rH  rŠ  rË   r7  rC   rC   rC   rD   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))r7  rP   )r<   rù   rú   rC   rC   rD   rÝ   ü  s    zCircle.__str__r!  c             K   s&   t j| ||d |d f|Ž || _dS )a6  
        Create true circle at center *xy* = (*x*, *y*) with given
        *radius*.  Unlike :class:`~matplotlib.patches.CirclePolygon`
        which is a polygonal approximation, this uses Bezier splines
        and is much closer to a scale-free circle.

        Valid kwargs are:
        %(Patch)s

        r1  N)rØ   r'   rP   )r<   rÄ   rP   rB   rC   rC   rD   r'     s    zCircle.__init__c             C   s   d|  | _ | _d| _dS )zl
        Set the radius of the circle

        Parameters
        ----------
        radius : float
        r1  TN)rÿ   r   r|   )r<   rP   rC   rC   rD   rI    s    zCircle.set_radiusc             C   s
   | j d S )z1
        Return the radius of the circle
        g       @)rÿ   )r<   rC   rC   rD   Ú
get_radius  s    zCircle.get_radiusN)r!  )rÆ   rÇ   rÈ   rÉ   rÝ   r   ró   r'   rI  r‹  rË   rP   rC   rC   rC   rD   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 :class:`~.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))r7  rÿ   r   rø   r9  r:  )r<   rù   rú   rC   rC   rD   rÝ   0  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, optional
            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

        r?   FzArc objects can not be filledN)Ú
setdefaultr”   rØ   r'   r9  r:  )	r<   rÄ   rÿ   r   rø   r9  r:  rB   r?   rC   rC   rD   r'   7  s    &zArc.__init__c                s  t | dƒstdƒ‚| jƒ  | j| jƒ}| j| jƒ}dd„ }|| j|| ƒ}|| j|| ƒ}| j	ƒ j
||fƒ\}}d}||k rž||k ržtj||ƒ| _tj| |ƒS dd	„ ‰ ‡ fd
d„}tjƒ }	tj| jjƒ| j	ƒ jƒ  }
|	j|
ƒ}	tƒ }x¬t|	jdd… |	jdd… ƒD ]Š\}}|\}}|\}}xn|||||ƒD ]\\}}tj|ƒ}|dk �rVdtj | }tj|ƒ}||  k �ot|k n  �r,|j|ƒ �q,W �qW t|ƒ|g }|}tj |ƒ}|	j!tj"|ƒtj#|ƒfƒ}| j}x>|D ]6}|�r tj||dƒ| _tj| |ƒ d}nd}|}�qÔW || _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.*

          http://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
           :meth:`matplotlib.path.Path.arc`.
        Úaxesz'Arcs can only be used in Axes instancesc             S   s4   t j| ƒ} t j| ƒ}t j| ƒ}t jt j|| |ƒƒS )N)r]   Údeg2radÚcosÚsinÚrad2degÚarctan2)Úthetar'  rT   rU   rC   rC   rD   Útheta_stretch¢  s    


zArc.draw.<locals>.theta_stretchg      ð?gÿéJûžØ¿>g      à?c             s   sê   ||  }|| }|| ||  }| | ||  }|| }|| }	|	dkrn|| | }
| | | }|
|fV  nx|	dkræ|dk r„d}nd}t j|	ƒ}xRdD ]J}|| || | |  | }
| | |t j|ƒ |  | }|
|fV  q˜W d S )Ng        ç      ð?g      ð¿ç      ð¿)r—  r˜  )r]   r  r>  )r  r  r	  r
  rP  rQ  Zdr2ÚDZD2ZdiscrimrT   rU   Zsign_dyZsqrt_discrimÚsignrC   rC   rD   Úiter_circle_intersect_on_line±  s&    

 z/Arc.draw.<locals>.iter_circle_intersect_on_linec             3   sº   d}|| k r||  }}n
| | }}||k r6|| }}n
|| }}||8 }||8 }||7 }||7 }xTˆ | |||ƒD ]B\}	}
||	  koŠ|kn  rp||
  ko¢|kn  rp|	|
fV  qpW d S )Ng•Ö&è.>rC   )r  r  r	  r
  ÚepsilonZx0eZx1eZy0eZy1erT   rU   )r›  rC   rD   Ú!iter_circle_intersect_on_line_segË  s    

0z3Arc.draw.<locals>.iter_circle_intersect_on_line_segNr   r   r1  é   FTgø\!ÛÈ Agø\!ÛÈAr2  )$ÚhasattrÚRuntimeErrorr‰  rÂ   rÿ   rÃ   r   r9  r:  rE   Útransform_pointr   r@  r#  r   r¿   r  r	   r  r�  r  ÚinvertedÚtransformedÚsetÚzipr\   r]   ÚarccosÚpir“  ÚaddÚsortedr�  rS   r‘  r’  )r<   rµ   rÿ   r   r–  r9  r:  Z	inv_errorr�  Zbox_pathZbox_path_transformZthetasÚp0Úp1r  r  r	  r
  rT   rU   r•  Z
last_thetaZ
theta1_radrd   Zpath_originalrC   )r›  rD   r¿   f  sX    2

(





zArc.drawN)rŒ  rŒ  r�  )rÆ   rÇ   rÈ   rÉ   rÝ   r   ró   r'   r   rÎ   r¿   rC   rC   rC   rD   rÙ   $  s    -Tc             C   s®   |dkri }|j ƒ }|jddƒ}|j|ƒ}| j|ƒ}|j\}}}}	||d 8 }||d 8 }||7 }|	|7 }	t||f||	|d�}
|
jtjƒ ƒ |
j	dƒ |
j
|ƒ |
j|ƒ dS )ad  
    This is a debug function to draw a rectangle around the bounding
    box returned by
    :meth:`~matplotlib.artist.Artist.get_window_extent` of an artist,
    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Úpadrk  g       @)rÄ   rÿ   r   r?   F)ÚcopyÚpoprë   rÁ   ÚboundsrÏ   ro   r	   rv   Úset_clip_onr;   r¿   )r   rµ   rÞ   r?   r¬  r  r  r�   rŒ   r  r8  rC   rC   rD   Úbbox_artist  s&    




r±  r€  c       	      C   sN   | j \}}}}t||f|||dd�}|dk	r6|j|ƒ |jdƒ |j|ƒ dS )zâ
    This is a debug function to draw a rectangle around the bounding
    box returned by
    :meth:`~matplotlib.artist.Artist.get_window_extent` of an artist,
    to test whether the artist is returning the correct bbox.
    F)rÄ   rÿ   r   r   r?   N)r¯  rÏ   ro   r°  r¿   )	r  rµ   r=   rH   r  r�   rŒ   r  r8  rC   rC   rD   Ú	draw_bbox(  s    

r²  r1  c                s‚   dd„ t | Ž D ƒ‰ djdd„ ˆ D ƒƒ}d|djdd„ t | d ˆ ƒD ƒƒ|f‡ fd	d„| d
d… D ƒ|df•}tjdj|ƒd| ƒS )zR
    Given the list of list of strings, return a string of REST table format.
    c             S   s   g | ]}t d d„ |D ƒƒ‘qS )c             s   s   | ]}t |ƒV  qd S )N)r:   )rV   ÚcellrC   rC   rD   rY   A  s    z+_pprint_table.<locals>.<listcomp>.<genexpr>)Úmax)rV   ÚcolumnrC   rC   rD   ú
<listcomp>A  s    z!_pprint_table.<locals>.<listcomp>z   c             s   s   | ]}d | V  qdS )ú=NrC   )rV   ÚclrC   rC   rD   rY   B  s    z _pprint_table.<locals>.<genexpr>Ú c             s   s   | ]\}}|j |ƒV  qd S )N)Úljust)rV   r³  r¸  rC   rC   rD   rY   F  s    r   c                s&   g | ]}d j dd„ t|ˆ ƒD ƒƒ‘qS )z   c             s   s   | ]\}}|j |ƒV  qd S )N)rº  )rV   r³  r¸  rC   rC   rD   rY   H  s    z+_pprint_table.<locals>.<listcomp>.<genexpr>)Újoinr¥  )rV   Úrow)Úcol_lenrC   rD   r¶  H  s   r   NÚ
ú )r¥  r»  ÚtextwrapÚindent)ÚtableÚleadingspaceÚtable_formatstrr   rC   )r½  rD   Ú_pprint_table=  s    
rÅ  c             C   sŒ   ddl }dddgg}xnt| jƒ ƒD ]^\}}|j|jƒ}|jrfdjtdj|j	t
|jƒ d… |jƒƒ}nd}|j|jd	| |gƒ q"W t|ƒS )
z¿
    A helper function for the _Style class.  Given the dictionary of
    {stylename: styleclass}, return a formatted string listing all the
    styles. Used to update the documentation.
    r   NZClassÚNameZAttrsz, z{}={}ÚNonez``%s``)Úinspectr©  ÚitemsÚgetfullargspecr'   Údefaultsr»  r`   Úformatr  r:   ÚappendrÆ   rÅ  )Ú_stylesrÈ  Z_tableÚnameÚclsÚspecÚargstrrC   rC   rD   Ú_pprint_stylesP  s    $rÓ  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 '{}' )rÌ  r»  r`   r©  )rÎ  rC   rC   rD   Ú_simpleprint_stylesh  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 n  tk
rL   td| ƒ‚Y nX y(dd„ |dd	… D ƒ}d
d„ |D ƒ}W n  tk
r–   td| ƒ‚Y nX |j|ƒ |f |ŽS )zP
        return the instance of the subclass with the given style name.
        r¿  r¹  ú,r   zUnknown style : %sc             S   s   g | ]}|j d ƒ‘qS )r·  )ra   )rV   ÚcsrC   rC   rD   r¶  ‡  s    z"_Style.__new__.<locals>.<listcomp>r   Nc             S   s   i | ]\}}t |ƒ|“qS rC   )r…   )rV   r€  rG  rC   rC   rD   ú
<dictcomp>ˆ  s    z"_Style.__new__.<locals>.<dictcomp>zIncorrect style argument : %s)Úreplacera   r’   Ú_style_listÚKeyErrorr”   r;   )rÐ  Z	stylenameÚkwZ_listÚ_nameÚ_clsZ
_args_pairÚ_argsrC   rC   rD   Ú__new__w  s    
z_Style.__new__c             C   s   | j S )zP
        A class method which returns a dictionary of available styles.
        )rÛ  )rÐ  rC   rC   rD   Ú
get_styles�  s    z_Style.get_stylesc             C   s
   t | jƒS )zP
        A class method which returns a string of the available styles.
        )rÓ  rÛ  )rÐ  rC   rC   rD   Úpprint_styles–  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”   rÛ  )rÐ  rÏ  ÚstylerC   rC   rD   Úregister�  s    z_Style.registerN)	rÆ   rÇ   rÈ   rÉ   rá  Úclassmethodrâ  rã  rç  rC   rC   rC   rD   rÖ  q  s
   rÖ  )rÏ  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)rÏ  )r°   r±   Ú_register_stylerÆ   r’   )Z
style_listrÐ  rÏ  rC   rC   rD   ré  ©  s    ré  c               @   s  e Zd ZdZi Z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eeƒG dd„ deƒƒZe�rejeƒdeeƒi ZdS )ÚBoxStylea„  
    :class:`BoxStyle` is a container class which defines several
    boxstyle classes, which are used for :class:`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")

    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 :class:`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_  
        :class:`BBoxTransmuterBase` and its derivatives are used to make a
        fancy box around a given rectangle. The :meth:`__call__` method
        returns the :class:`~matplotlib.path.Path` of the fancy box. This
        class is not an artist and actual drawing of the fancy box is done
        by the :class:`FancyBboxPatch` class.
        c             C   s   t dƒ‚dS )aƒ  
            The transmute method is a very core of the
            :class:`BboxTransmuter` class and must be overridden in the
            subclasses. It receives the location and size of the
            rectangle, and the mutation_size, with which the amount of
            padding and etc. will be scaled. It returns a
            :class:`~matplotlib.path.Path` instance.
            zDerived must overrideN)rÀ   )r<   r  r  rÿ   r   Úmutation_sizerC   rC   rD   Ú	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 )aH  
            Given the location and size of the box, return the path of
            the box around it.

              - *x0*, *y0*, *width*, *height* : location and size of the box
              - *mutation_size* : a reference scale for the mutation.
              - *aspect_ratio* : aspect-ration for the mutation.
            Nr   )rì  r\   r[   r   )
r<   r  r  rÿ   r   rë  Úaspect_ratiorI   r\   r[   rC   rC   rD   Ú__call__í  s     
zBoxStyle._Base.__call__N)rí  )rÆ   rÇ   rÈ   rÉ   rì  rï  rC   rC   rC   rD   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 simple square box.
        ç333333Ó?c                s   || _ tƒ jƒ  dS )zB
             *pad*
                amount of padding
            N)r¬  r]  r'   )r<   r¬  )rg  rC   rD   r'     s    zBoxStyle.Square.__init__c             C   s�   || j  }|d|  |d|   }}|| ||  }}|| ||  }}||f||f||f||f||fg}	tjgtjgd  tjg }
t|	|
ƒS )Nr1  rK   )r¬  r   r_   r?  rC  )r<   r  r  rÿ   r   rë  r¬  r	  r
  r\   r[   rC   rC   rD   rì    s    
"zBoxStyle.Square.transmute)rð  )rÆ   rÇ   rÈ   rÉ   r'   rì  rh  rC   rC   )rg  rD   Ú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 simple circle box.ç333333Ó?c                s   || _ tƒ jƒ  dS )z’
            Parameters
            ----------
            pad : float
                The amount of padding around the original box.
            N)r¬  r]  r'   )r<   r¬  )rg  rC   rD   r'   &  s    zBoxStyle.Circle.__init__c             C   s`   || j  }|d|  |d|   }}|| ||  }}tj||d  ||d  ft||ƒd ƒS )Nr1  )r¬  r   Úcircler´  )r<   r  r  rÿ   r   rë  r¬  rC   rC   rD   rì  0  s
    
zBoxStyle.Circle.transmute)rò  )rÆ   rÇ   rÈ   rÉ   r'   rì  rh  rC   rC   )rg  rD   rÐ   #  s   
rÐ   c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )zBoxStyle.LArrowz"
        (left) Arrow Box
        ç333333Ó?c                s   || _ tƒ jƒ  d S )N)r¬  r]  r'   )r<   r¬  )rg  rC   rD   r'   >  s    zBoxStyle.LArrow.__init__c          
   C   s   || j  }|d|  |d|   }}|| ||  }}|| ||  }}|| d }	|	d }
||d  }||
 |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g	}t||ƒ}|S )Ng       @g      à?gffffffö?)r¬  r   r_   r?  rC  )r<   r  r  rÿ   r   rë  r¬  r	  r
  rP  ÚdxxÚcpÚcomrI   rC   rC   rD   rì  B  s     
 
zBoxStyle.LArrow.transmute)rô  )rÆ   rÇ   rÈ   rÉ   r'   rì  rh  rC   rC   )rg  rD   ÚLArrow9  s   rø  c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )zBoxStyle.RArrowz#
        (right) Arrow Box
        ç333333Ó?c                s   t ƒ j|ƒ d S )N)r]  r'   )r<   r¬  )rg  rC   rD   r'   e  s    zBoxStyle.RArrow.__init__c             C   sF   t jj| |||||ƒ}d| | |jd d …df  |jd d …df< |S )Nr1  r   )rê  rø  rì  r\   )r<   r  r  rÿ   r   rë  ÚprC   rC   rD   rì  h  s    
,zBoxStyle.RArrow.transmute)rù  )rÆ   rÇ   rÈ   rÉ   r'   rì  rh  rC   rC   )rg  rD   ÚRArrow_  s   rû  c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )zBoxStyle.DArrowz$
        (Double) Arrow Box
        ç333333Ó?c                s   || _ tƒ jƒ  d S )N)r¬  r]  r'   )r<   r¬  )rg  rC   rD   r'   v  s    zBoxStyle.DArrow.__init__c             C   s$  || j  }|d|  }|| ||  }}|| ||  }}|| d }	|	d }
||d  }||
 |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g}t||ƒ}|S )Ng       @r1  g      à?gffffffö?)r¬  r   r_   r?  rC  )r<   r  r  rÿ   r   rë  r¬  r	  r
  rP  rõ  rö  r÷  rI   rC   rC   rD   rì  z  s.    


zBoxStyle.DArrow.transmute)rü  )rÆ   rÇ   rÈ   rÉ   r'   rì  rh  rC   rC   )rg  rD   ÚDArrown  s   rý  c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )	zBoxStyle.Roundz+
        A box with round corners.
        ç333333Ó?Nc                s   || _ || _tƒ jƒ  dS )z”
            *pad*
              amount of padding

            *rounding_size*
              rounding radius of corners. *pad* if None
            N)r¬  Úrounding_sizer]  r'   )r<   r¬  rÿ  )rg  rC   rD   r'   ¦  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 )Ng       @)r¬  rÿ  r   r_   r?  ÚCURVE3rC  )r<   r  r  rÿ   r   rë  r¬  Údrr	  r
  rö  r÷  rI   rC   rC   rD   rì  ²  s:    






zBoxStyle.Round.transmute)rþ  N)rÆ   rÇ   rÈ   rÉ   r'   rì  rh  rC   rC   )rg  rD   ÚRound   s   r  c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )	zBoxStyle.Round4z/
        Another box with round edges.
        ç333333Ó?Nc                s   || _ || _tƒ jƒ  dS )z�
            *pad*
              amount of padding

            *rounding_size*
              rounding size of edges. *pad* if None
            N)r¬  rÿ  r]  r'   )r<   r¬  rÿ  )rg  rC   rD   r'   ä  s    zBoxStyle.Round4.__init__c             C   s\  || 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       @r1  )r¬  rÿ  r   r_   ÚCURVE4rC  )r<   r  r  rÿ   r   rë  r¬  r  r	  r
  rö  r÷  rI   rC   rC   rD   rì  ð  s,    
""""

zBoxStyle.Round4.transmute)r  N)rÆ   rÇ   rÈ   rÉ   r'   rì  rh  rC   rC   )rg  rD   Ú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.Sawtoothz!
        A sawtooth box.
        ç333333Ó?Nc                s   || _ || _tƒ jƒ  dS )zŠ
            *pad*
              amount of padding

            *tooth_size*
              size of the sawtooth. pad* if None
            N)r¬  Ú
tooth_sizer]  r'   )r<   r¬  r  )rg  rC   rD   r'   	  s    zBoxStyle.Sawtooth.__init__c             C   sX  || j  }| jd kr$| j d | }n
| j| }|d }|d|  | |d|  |  }}ttj|| |d  ƒƒd }	|| |	 }
ttj|| |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      à?g       @r1  r   )r¬  r  Úintr]   r!   Úaranger¥  )r<   r  r  rÿ   r   rë  r¬  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_verticesrC   rC   rD   Ú_get_sawtooth_vertices%	  sV    


z(BoxStyle.Sawtooth._get_sawtooth_verticesc             C   s"   | j |||||ƒ}t|dd�}|S )NT)r.  )r  r   )r<   r  r  rÿ   r   rë  r
  rI   rC   rC   rD   rì  o	  s    
zBoxStyle.Sawtooth.transmute)r  N)rÆ   rÇ   rÈ   rÉ   r'   r  rì  rh  rC   rC   )rg  rD   ÚSawtooth	  s   Jr  c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )	zBoxStyle.RoundtoothzA rounded tooth box.ç333333Ó?Nc                s   t ƒ j||ƒ dS )zŠ
            *pad*
              amount of padding

            *tooth_size*
              size of the sawtooth. pad* if None
            N)r]  r'   )r<   r¬  r  )rg  rC   rD   r'   x	  s    zBoxStyle.Roundtooth.__init__c             C   sf   | j |||||ƒ}tjtj|ƒ|d ggdd�}tjgtjtjgt|ƒd d   tjg }t||ƒS )Nr   )Úaxisr   r1  )	r  r]   r3  r[  r   r_   r   r:   rC  )r<   r  r  rÿ   r   rë  r
  r[   rC   rC   rD   rì  ‚	  s    "
zBoxStyle.Roundtooth.transmute)r  N)rÆ   rÇ   rÈ   rÉ   r'   rì  rh  rC   rC   )rg  rD   Ú
Roundtoothu	  s   
r  ÚAvailableBoxstylesN)rÆ   rÇ   rÈ   rÉ   rÛ  Úobjectrå  ré  rñ  rÐ   rø  rû  rý  r  r  r  r  rÈ  ÚcleandocrÓ  rC   rC   rC   rD   rê  ±  s0    1%1=4arê  )r  ZListBoxstylesc               @   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Ú   aW  
    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 `.BoxTransmuterBase` and its derived classes.
    Tc             C   s$   | j jd }|| j| j| j| jf S )Nz((%g, %g), width=%g, height=%g))rg  rÆ   Ú_xÚ_yrö   r÷   )r<   r–   rC   rC   rD   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, optional, 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   ÚcustomNz7bbox_transmuter argument is needed with custom boxstyleT)r   r'   r  r  rö   r÷   r”   Ú_bbox_transmuterÚset_boxstyleÚ_mutation_scaleÚ_mutation_aspectr|   )	r<   rÄ   rÿ   r   ÚboxstyleÚbbox_transmuterÚmutation_scaleÚmutation_aspectrB   rC   rC   rD   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.

        *boxstyle* can be a string with boxstyle name with optional
        comma-separated attributes. Alternatively, the attrs can
        be provided as keywords::

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

        Old attrs simply are forgotten.

        Without argument (or with *boxstyle* = None), it returns
        available box styles.

        The following boxstyles are available:
        %(AvailableBoxstyles)s

        ACCEPTS: %(ListBoxstyles)s
        NT)rê  rã  rL   rå  Úcallabler  r|   )r<   r  rÝ  rC   rC   rD   r  ê	  s    zFancyBboxPatch.set_boxstylec             C   s   || _ d| _dS )zf
        Set the mutation scale.

        Parameters
        ----------
        scale : float
        TN)r  r|   )r<   r'  rC   rC   rD   Úset_mutation_scale	
  s    z!FancyBboxPatch.set_mutation_scalec             C   s   | j S )zReturn the mutation scale.)r  )r<   rC   rC   rD   Úget_mutation_scale
  s    z!FancyBboxPatch.get_mutation_scalec             C   s   || _ d| _dS )zz
        Set the aspect ratio of the bbox mutation.

        Parameters
        ----------
        aspect : float
        TN)r  r|   )r<   ÚaspectrC   rC   rD   Úset_mutation_aspect
  s    z"FancyBboxPatch.set_mutation_aspectc             C   s   | j S )z-Return the aspect ratio of the bbox mutation.)r  )r<   rC   rC   rD   Úget_mutation_aspect#
  s    z"FancyBboxPatch.get_mutation_aspectc             C   s   | j S )zReturn the boxstyle object.)r  )r<   rC   rC   rD   Ú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.)r%  r  r  rö   r÷   r!  r$  )r<   r#  rC   rC   rD   rF   +
  s
    
zFancyBboxPatch.get_pathc             C   s   | j S )z'Return the left coord of the rectangle.)r  )r<   rC   rC   rD   r  5
  s    zFancyBboxPatch.get_xc             C   s   | j S )z)Return the bottom coord of the rectangle.)r  )r<   rC   rC   rD   r  9
  s    zFancyBboxPatch.get_yc             C   s   | j S )z"Return the width of the rectangle.)rö   )r<   rC   rC   rD   r  =
  s    zFancyBboxPatch.get_widthc             C   s   | j S )z#Return the height of the rectangle.)r÷   )r<   rC   rC   rD   r  A
  s    zFancyBboxPatch.get_heightc             C   s   || _ d| _dS )zo
        Set the left coord of the rectangle.

        Parameters
        ----------
        x : float
        TN)r  r|   )r<   rT   rC   rC   rD   r  E
  s    zFancyBboxPatch.set_xc             C   s   || _ d| _dS )zq
        Set the bottom coord of the rectangle.

        Parameters
        ----------
        y : float
        TN)r  r|   )r<   rU   rC   rC   rD   r  P
  s    zFancyBboxPatch.set_yc             C   s   || _ d| _dS )zc
        Set the rectangle width.

        Parameters
        ----------
        w : float
        TN)rö   r|   )r<   rŒ   rC   rC   rD   r  [
  s    zFancyBboxPatch.set_widthc             C   s   || _ d| _dS )zd
        Set the rectangle height.

        Parameters
        ----------
        h : float
        TN)r÷   r|   )r<   r  rC   rC   rD   r  f
  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)r:   r  r  rö   r÷   r|   )r<   r  r  r�   rŒ   r  rC   rC   rD   r  q
  s    zFancyBboxPatch.set_boundsc             C   s   t jj| j| j| j| jƒS )z$Return the `.Bbox` of the rectangle.)r	   r  Úfrom_boundsr  r  rö   r÷   )r<   rC   rC   rD   r  ‹
  s    zFancyBboxPatch.get_bbox)r!   Nr  N)N)rÆ   rÇ   rÈ   rÉ   r~   rÝ   r   ró   r'   r  r   r!  r#  r$  r%  rF   r  r  r  r  r  r  r  r  r  r  rC   rC   rC   rD   rÚ   —	  s4      >
c               @   s¶   e Zd ZdZi Z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r²ejeƒdeeƒi ZdS )ÚConnectionStylea0  
    :class:`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
    :class:`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 :class:`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)rT   rU   )r<   rÄ   rC   rC   rD   r'   É
  s    z*ConnectionStyle._Base.SimpleEvent.__init__N)rÆ   rÇ   rÈ   r'   rC   rC   rC   rD   Ú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(  re   )Ú
xy_displayÚxy_event)ÚpatchArC   rD   ÚinsideAÖ
  s    z,ConnectionStyle._Base._clip.<locals>.insideAc                s   t jj| ƒ}ˆ j|ƒd S )Nr   )r'  rå  r(  re   )r)  r*  )ÚpatchBrC   rD   ÚinsideBâ
  s    z,ConnectionStyle._Base._clip.<locals>.insideB)r   r”   )r<   rI   r+  r-  r,  rW  rX  r.  rC   )r+  r-  rD   Ú_clipÌ
  s    	

zConnectionStyle._Base._clipc             C   s„   |r@t |jd |fžŽ }yt||ƒ\}}W n tk
r>   Y nX |r€t |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   r2  )r   r\   r   r”   )r<   rI   ÚshrinkAÚshrinkBr,  rW  r.  rX  rC   rC   rD   Ú_shrinkï
  s    zConnectionStyle._Base._shrinkç       @Nc       
      C   s,   | j ||ƒ}| j|||ƒ}| j|||ƒ}	|	S )z�
            Calls the *connect* method to create a path between *posA*
             and *posB*. The path is clipped and shrunken.
            )Úconnectr/  r2  )
r<   ÚposAÚposBr0  r1  r+  r-  rI   Zclipped_pathZshrunk_pathrC   rC   rD   rï    s    zConnectionStyle._Base.__call__)r3  r3  NN)rÆ   rÇ   rÈ   rÉ   r(  r/  r2  rï  rC   rC   rC   rD   rå  »
  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)r<   r8  rC   rC   rD   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       @)r8  r   r_   r   )r<   r5  r6  r	  r
  rv  rw  Zx12Zy12rP  rQ  ÚfrS  Úcyr\   r[   rC   rC   rD   r4     s    
zConnectionStyle.Arc3.connectN)r7  )rÆ   rÇ   rÈ   rÉ   r'   r4  rC   rC   rC   rD   Ú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)r<   r=  r>  rC   rC   rD   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)
r~  r‘  Úradiansr=  r’  r>  r   r   r_   r   )r<   r5  r6  r	  r
  rv  rw  ÚcosAÚsinAÚcosBÚsinBrS  r:  r\   r[   rC   rC   rD   r4  H  s    
zConnectionStyle.Angle3.connectN)r<  r   )rÆ   rÇ   rÈ   rÉ   r'   r4  rC   rC   rC   rD   ÚAngle33  s   
rD  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>  r8  )r<   r=  r>  r8  rC   rC   rD   r'   c  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   r_   r8  rÍ  r?  r]   rM  Úextendr   )r<   r5  r6  r	  r
  rv  rw  r@  rA  rB  rC  rS  r:  r\   r[   Údx1Údy1Úd1Úf1Údx2Údy2Úd2Úf2rC   rC   rD   r4  t  s4    




zConnectionStyle.Angle.connectN)r<  r   rE  )rÆ   rÇ   rÈ   rÉ   r'   r4  rC   rC   rC   rD   ÚAngleY  s   
rO  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ÚarmBr8  )r<   r=  r>  rQ  rR  r8  rC   rC   rD   r'   ¡  s
    zConnectionStyle.Arc.__init__c             C   sv  |\}}|\}}||fg}g }t jg}	| jržtjtj| jƒƒ}
tjtj| jƒƒ}| j| j }|j	|||
  |||  fƒ | j}|j	|||
  |||  fƒ | j
�rÐt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      à?r2  r2  r2  )r   r_   rQ  r~  r‘  r?  r=  r’  r8  rÍ  rR  r>  rF  r?  r   )r<   r5  r6  r	  r
  rv  rw  r\   Zroundedr[   r@  rA  ÚdrB  rC  Zx_armBZy_armBÚxpZyprP  rQ  ÚddrC   rC   rD   r4  º  sZ    





zConnectionStyle.Arc.connect)r   r   NNrP  )rÆ   rÇ   rÈ   rÉ   r'   r4  rC   rC   rC   rD   rÙ   —  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)rQ  rR  Úfractionrø   )r<   rQ  rR  rX  rø   rC   rC   rD   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~  Úatan2rQ  rR  rø   r]   r�  r’  r‘  r´  rX  r   r_   r?  )r<   r5  r6  r	  r
  Zx20Zy20rv  rw  r9  rP  rQ  rU  ÚddxÚddyrQ  rR  Ztheta0ZdthetaÚdlZdLZdd2Zarmr9  Zcx1Zcy1Zcx2Zcy2r\   r[   rC   rC   rD   r4    s<    &

zConnectionStyle.Bar.connect)rV  rV  rW  N)rÆ   rÇ   rÈ   rÉ   r'   r4  rC   rC   rC   rD   ÚBarõ  s   
r]  ÚAvailableConnectorstylesN)rÆ   rÇ   rÈ   rÉ   rÛ  r  rå  ré  r;  rD  rO  rÙ   r]  rÈ  r  rÓ  rC   rC   rC   rD   r'  ‘
  s    &T#%=]Hr'  c       
      C   sL   | | ||  }}||| ||  d  }| ||  |||   }}	||	fS )zj
    find a point along a line connecting (x0, y0) -- (x1, y1) whose
    distance from (x0, y0) is d.
    g      à?rC   )
r  r  r	  r
  rS  rP  rQ  Úffrv  rw  rC   rC   rD   Ú_point_along_a_lineC  s    r`  c               @   sÜ  e Zd ZdZi Z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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e�rØejeƒd0eeƒi Zd1S )2Ú
ArrowStylea«  
    :class:`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 :class:`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 :class:`Path` instance and a boolean
    value. *path* is a :class:`Path` instance along which the arrow
    will be drawn. *mutation_size* and *aspect_ratio* have the same
    meaning as in :class:`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.
            r1  r   r   z,'path' is not a valid quadratic Bezier curve)ÚlistÚiter_segmentsr:   r   r_   r   r”   )rI   ÚsegmentsrC   rC   rD   Úensure_quadratic_bezier‡  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À   )r<   rI   rë  r   rC   rC   rD   rì  –  s    zArrowStyle._Base.transmuteç      ð?c             C   sì   t |ƒ}|dk	rÚ|jdd… |jdd…  }}|dd…df | |dd…df< t||ƒ}| j|||ƒ\}}	tj|	ƒrÐg }
xNt|ƒD ]B}|j|j }}|dd…df | |dd…df< |
jt||ƒƒ q‚W |
|	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   )	r   r\   r[   r   rì  r]   Úiterabler¥  rÍ  )r<   rI   rë  r   rî  r\   r[   Zpath_shrunkZpath_mutatedÚfillableÚ	path_listrú  rG  r„   rC   rC   rD   rï  ¤  s"     


 
zArrowStyle._Base.__call__N)rf  )rÆ   rÇ   rÈ   rÉ   Ústaticmethodre  rì  rï  rC   rC   rC   rD   rå  v  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Úfillendr]  r'   )r<   rm  rn  ro  rp  r_  r^  )rg  rC   rD   r'   Í  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   )r]   rM  r   r_   r?  )r<   r  r  r	  r
  Ú	head_distÚcos_tÚsin_tr   rP  rQ  Zcp_distanceZpad_projectedrZ  r[  rG  rH  rK  rL  Úvertices_arrowÚcodes_arrowrC   rC   rD   Ú_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�r–t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   r1  FTrY  r2  r2  )r_  r^  r]   rM  r\   rm  rv  rn  r   r3  r[   ro  r?  rC  rÍ  rp  )r<   rI   rë  r   r_  r^  rq  rr  rs  r  r  r	  r
  Zhas_begin_arrowÚ	verticesAÚcodesAZddxAZddyArv  rw  Zx3Zy3Zhas_end_arrowÚ	verticesBÚcodesBZddxBZddyBr#  Z	_fillablerú  r„   rC   rC   rD   rì    sL    





zArrowStyle._Curve.transmute)NNFFrk  rl  )rÆ   rÇ   rÈ   rÉ   r'   rv  rì  rh  rC   rC   )rg  rD   Ú_CurveÅ  s     +r{  ú-)rÏ  c                   s    e Zd ZdZ‡ fdd„Z‡  ZS )zArrowStyle.Curvez8
        A simple curve without any arrow head.
        c                s   t ƒ jddd� d S )NF)rm  rn  )r]  r'   )r<   )rg  rC   rD   r'   N  s    zArrowStyle.Curve.__init__)rÆ   rÇ   rÈ   rÉ   r'   rh  rC   rC   )rg  rD   ÚCurveH  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, optional, default : 0.4
                Length of the arrow head

            head_width : float, optional, default : 0.2
                Width of the arrow head
            TF)rm  rn  r_  r^  N)r]  r'   )r<   r_  r^  )rg  rC   rD   r'   W  s    

zArrowStyle.CurveA.__init__)r~  r  )rÆ   rÇ   rÈ   rÉ   r'   rh  rC   rC   )rg  rD   ÚCurveAQ  s   r€  z->c                   s"   e Zd ZdZd‡ fdd„	Z‡  ZS )zArrowStyle.CurveBz8
        An arrow with a head at its end point.
        çš™™™™™Ù?çš™™™™™É?c                s   t ƒ jdd||d� dS )zþ
            Parameters
            ----------
            head_length : float, optional, default : 0.4
                Length of the arrow head

            head_width : float, optional, default : 0.2
                Width of the arrow head
            FT)rm  rn  r_  r^  N)r]  r'   )r<   r_  r^  )rg  rC   rD   r'   j  s    

zArrowStyle.CurveB.__init__)r�  r‚  )rÆ   rÇ   rÈ   rÉ   r'   rh  rC   rC   )rg  rD   ÚCurveBd  s   rƒ  z<->c                   s"   e Zd ZdZd‡ fdd„	Z‡  ZS )zArrowStyle.CurveABzJ
        An 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, optional, default : 0.4
                Length of the arrow head

            head_width : float, optional, default : 0.2
                Width of the arrow head
            T)rm  rn  r_  r^  N)r]  r'   )r<   r_  r^  )rg  rC   rD   r'   }  s    

zArrowStyle.CurveAB.__init__)r„  r…  )rÆ   rÇ   rÈ   rÉ   r'   rh  rC   rC   )rg  rD   ÚCurveABw  s   r†  z<|-c                   s"   e Zd ZdZd‡ fdd„	Z‡  ZS )zArrowStyle.CurveFilledAzB
        An arrow with filled triangle head at the begin.
        çš™™™™™Ù?çš™™™™™É?c                s   t ƒ jdddd||d� dS )zþ
            Parameters
            ----------
            head_length : float, optional, default : 0.4
                Length of the arrow head

            head_width : float, optional, default : 0.2
                Width of the arrow head
            TF)rm  rn  ro  rp  r_  r^  N)r]  r'   )r<   r_  r^  )rg  rC   rD   r'   �  s    

z ArrowStyle.CurveFilledA.__init__)r‡  rˆ  )rÆ   rÇ   rÈ   rÉ   r'   rh  rC   rC   )rg  rD   Ú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, optional, default : 0.4
                Length of the arrow head

            head_width : float, optional, default : 0.2
                Width of the arrow head
            FT)rm  rn  ro  rp  r_  r^  N)r]  r'   )r<   r_  r^  )rg  rC   rD   r'   ¤  s    

z ArrowStyle.CurveFilledB.__init__)rŠ  r‹  )rÆ   rÇ   rÈ   rÉ   r'   rh  rC   rC   )rg  rD   ÚCurveFilledBž  s   rŒ  z<|-|>c                   s"   e Zd ZdZd‡ fdd„	Z‡  ZS )zArrowStyle.CurveFilledABzC
        An arrow with filled triangle heads at both ends.
        çš™™™™™Ù?çš™™™™™É?c                s   t ƒ jdddd||d� dS )zþ
            Parameters
            ----------
            head_length : float, optional, default : 0.4
                Length of the arrow head

            head_width : float, optional, default : 0.2
                Width of the arrow head
            T)rm  rn  ro  rp  r_  r^  N)r]  r'   )r<   r_  r^  )rg  rC   rD   r'   ¸  s    

z!ArrowStyle.CurveFilledAB.__init__)r�  rŽ  )rÆ   rÇ   rÈ   rÉ   r'   rh  rC   rC   )rg  rD   ÚCurveFilledAB²  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)r<   r’  r“  r”  r•  r–  r—  r=  r>  r˜  r™  rC   rC   rD   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   r_   r?  )r<   r  r  rr  rs  rÿ   rb  rš  r	  r
  rv  rw  rP  rQ  rt  ru  rC   rC   rD   Ú_get_bracketÓ  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   r1  Fr2  rY  )r˜  r™  r’  r\   r   r›  r”  r–  rÍ  r[   r“  r•  r—  r]   r3  r   )r<   rI   rë  r   r˜  r™  Zvertices_listZ
codes_listr  r  r	  r
  rr  rs  rw  rx  ry  rz  r\   r[   rú  rC   rC   rD   rì  ç  s>    









zArrowStyle._Bracket.transmute)
NNr�  r�  r‘  r‘  NNNN)rÆ   rÇ   rÈ   r'   r›  rì  rC   rC   rC   rD   Ú_BracketÆ  s       
rœ  z]-[c                   s"   e Zd ZdZd‡ fdd„	Z‡  ZS )zArrowStyle.BracketABz:
        An arrow with a bracket(]) at both ends.
        ç      ð?çš™™™™™É?Nc          
      s    t ƒ jdd||||||d� dS )a€  
            Parameters
            ----------
            widthA : float, optional, default : 1.0
                Width of the bracket

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

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

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

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

            angleB : float, optional, default : None
                Angle between the bracket and the line
            T)r”  r–  r=  r•  r—  r>  N)r]  r'   )r<   r”  r–  r=  r•  r—  r>  )rg  rC   rD   r'     s    
zArrowStyle.BracketAB.__init__)r�  rž  Nr�  rž  N)rÆ   rÇ   rÈ   rÉ   r'   rh  rC   rC   )rg  rD   Ú	BracketAB  s    rŸ  z]-c                   s"   e Zd ZdZd‡ fdd„	Z‡  ZS )zArrowStyle.BracketAz9
        An arrow with a bracket(])  at its end.
        ç      ð?çš™™™™™É?Nc                s   t ƒ jdd|||d� dS )a]  
            Parameters
            ----------
            widthA : float, optional, default : 1.0
                Width of the bracket

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

            angleA : float, optional, default : None
                Angle between the bracket and the line
            TN)r”  r–  r=  )r]  r'   )r<   r”  r–  r=  )rg  rC   rD   r'   ;  s    
zArrowStyle.BracketA.__init__)r   r¡  N)rÆ   rÇ   rÈ   rÉ   r'   rh  rC   rC   )rg  rD   ÚBracketA5  s   r¢  z-[c                   s"   e Zd ZdZd‡ fdd„	Z‡  ZS )zArrowStyle.BracketBz9
        An arrow with a bracket([)  at its end.
        ç      ð?çš™™™™™É?Nc                s   t ƒ jdd|||d� dS )a]  
            Parameters
            ----------
            widthB : float, optional, default : 1.0
                Width of the bracket

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

            angleB : float, optional, default : None
                Angle between the bracket and the line
            NT)r•  r—  r>  )r]  r'   )r<   r•  r—  r>  )rg  rC   rD   r'   Q  s    
zArrowStyle.BracketB.__init__)r£  r¤  N)rÆ   rÇ   rÈ   rÉ   r'   rh  rC   rC   )rg  rD   ÚBracketBK  s   r¥  z|-|c                   s"   e Zd ZdZd‡ fdd„	Z‡  ZS )zArrowStyle.BarABz6
        An arrow with a bar(|) at both ends.
        ç      ð?Nc          
      s    t ƒ jdd|d||d|d� dS )aÈ  
            Parameters
            ----------
            widthA : float, optional, default : 1.0
                Width of the bracket

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

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

            angleB : float, optional, default : None
                Angle between the bracket and the line
            Tr   )r”  r–  r=  r•  r—  r>  N)r]  r'   )r<   r”  r=  r•  r>  )rg  rC   rD   r'   g  s    
zArrowStyle.BarAB.__init__)r¦  Nr¦  N)rÆ   rÇ   rÈ   rÉ   r'   rh  rC   rC   )rg  rD   ÚBarABa  s    r§  c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )	zArrowStyle.SimplezK
        A simple arrow. Only works with a quadratic Bezier curve.
        ç      à?çš™™™™™É?c                s$   |||  | _ | _| _tƒ jƒ  dS )a_  
            Parameters
            ----------
            head_length : float, optional, default : 0.5
                Length of the arrow head

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

            tail_width : float, optional, default : 0.2
                Width of the arrow tail
            N)r_  r^  Ú
tail_widthr]  r'   )r<   r_  r^  rª  )rg  rC   rD   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{®Gáz„?)Ú	toleranceg      à?g       @)Úwmr   r   r1  c             S   s   g | ]\}}|‘qS rC   rC   )rV   r„   rú  rC   rC   rD   r¶  Ë  s    z/ArrowStyle.Simple.transmute.<locals>.<listcomp>c             S   s   g | ]\}}|‘qS rC   rC   )rV   r„   rú  rC   rC   rD   r¶  Ë  s    T)re  r_  r   r   r
   r`  r^  r   rª  r   r   r_   r   r?  rC  )r<   rI   rë  r   r  r  r	  r
  rv  rw  r_  Úin_fÚ
arrow_pathZ	arrow_outZarrow_inÚx1nÚy1nr^  Ú	head_leftÚ
head_rightrª  Ú	tail_leftÚ
tail_rightÚ
patch_pathrC   rC   rD   rì  ”  sP    




zArrowStyle.Simple.transmute)r¨  r¨  r©  )rÆ   rÇ   rÈ   rÉ   r'   rì  rh  rC   rC   )rg  rD   ÚSimple}  s   r¶  c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )zArrowStyle.FancyzJ
        A fancy arrow. Only works with a quadratic Bezier curve.
        çš™™™™™Ù?c                s$   |||  | _ | _| _tƒ jƒ  dS )a_  
            Parameters
            ----------
            head_length : float, optional, default : 0.4
                Length of the arrow head

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

            tail_width : float, optional, default : 0.4
                Width of the arrow tail
            N)r_  r^  rª  r]  r'   )r<   r_  r^  rª  )rg  rC   rD   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{®Gáz„?)r«  g      à?gš™™™™™é?g       @g333333ã?)r¬  g      ð?g333333Ó?)Úw1r¬  Úw2r   r   r1  c             S   s   g | ]\}}|‘qS rC   rC   )rV   r„   rú  rC   rC   rD   r¶  %  s    z.ArrowStyle.Fancy.transmute.<locals>.<listcomp>c             S   s   g | ]\}}|‘qS rC   rC   )rV   r„   rú  rC   rC   rD   r¶  %  s    Tr2  )re  r_  r   r   r
   r`  r^  r   rª  r   r_   r?  r   rC  )r<   rI   rë  r   r  r  r	  r
  rv  rw  r_  r®  r­  Zpath_outZpath_inr¯  r°  Z	path_headZ	path_tailr^  Zhead_lZhead_rrª  r³  r´  Z
tail_startr²  r±  rµ  rC   rC   rD   rì  æ  s\    




zArrowStyle.Fancy.transmute)r·  r·  r·  )rÆ   rÇ   rÈ   rÉ   r'   rì  rh  rC   rC   )rg  rD   ÚFancyÏ  s   rº  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 )a  
            Parameters
            ----------
            tail_width : float, optional, default : 0.3
                Width of the tail

            shrink_factor : float, optional, default : 0.5
                Fraction of the arrow width at the middle point
            N)rª  Úshrink_factorr]  r'   )r<   rª  r½  )rg  rC   rD   r'   1  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       @)r¬  r   r   r1  c             S   s   g | ]\}}|‘qS rC   rC   )rV   r„   rú  rC   rC   rD   r¶  Q  s    z.ArrowStyle.Wedge.transmute.<locals>.<listcomp>c             S   s   g | ]\}}|‘qS rC   rC   )rV   r„   rú  rC   rC   rD   r¶  Q  s    T)	re  r   rª  r½  r   r_   r   r?  rC  )r<   rI   rë  r   r  r  r	  r
  rv  rw  r®  Zb_plusZb_minusrµ  rC   rC   rD   rì  ?  s    zArrowStyle.Wedge.transmute)r»  r¼  )rÆ   rÇ   rÈ   rÉ   r'   rì  rh  rC   rC   )rg  rD   rÓ   )  s   rÓ   ÚAvailableArrowstylesN)rÆ   rÇ   rÈ   rÉ   rÛ  r  rå  r{  ré  r}  r€  rƒ  r†  r‰  rŒ  r�  rœ  rŸ  r¢  r¥  r§  r¶  rº  rÓ   rÈ  r  rÓ  rC   rC   rC   rD   ra  O  sJ   #O M!QY+ra  )r¾  r^  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 ).ri  a%  
    A fancy arrow patch. It draws an arrow using the :class:`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   sP   | j d k	r4| j \\}}\}}| jjd||||f  S | jjdt| jƒf  S d S )Nz((%g, %g)->(%g, %g))z(%s))Ú
_posA_posBrg  rÆ   rÜ   Ú_path_original)r<   r	  r
  rv  rw  rC   rC   rD   rÝ   j  s    
zFancyArrowPatch.__str__NÚsimpleÚarc3r1  r   c             K   sæ   |dk	rt jddddd� |dk	r4t jddddd� tj| f|Ž |dk	r||dk	r||dkr|||g| _|dkrpd	}| j|ƒ n(|dkrœ|dkrœ|dk	rœd| _ntd
ƒ‚|| _|	| _|
| _	|| _
|| _| j|ƒ || _|| _| j|ƒ dS )aÿ
  
        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 : None, tuple, optional (default: None)
            (x,y) coordinates of arrow tail and arrow head respectively.

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

        arrowstyle : str or ArrowStyle, optional (default: 'simple')
            Describes how the fancy arrow will be
            drawn. It can be string of the available arrowstyle names,
            with optional comma-separated attributes, or an
            :class:`ArrowStyle` instance. The optional attributes are meant to
            be scaled with the *mutation_scale*. The following arrow styles are
            available:

            %(AvailableArrowstyles)s

        arrow_transmuter
            Ignored

        connectionstyle : str, ConnectionStyle, or None, optional
        (default: 'arc3')
            Describes how *posA* and *posB* are connected. It can be an
            instance of the :class:`ConnectionStyle` class or a string of the
            connectionstyle name, with optional comma-separated attributes. The
            following connection styles are available:

            %(AvailableConnectorstyles)s

        connector
            Ignored

        patchA, patchB : None, Patch, optional (default: None)
            Head and tail patch respectively. :class:`matplotlib.patch.Patch`
            instance.

        shrinkA, shrinkB : scalar, optional (default: 2)
            Shrinking factor of the tail and head of the arrow respectively

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

        mutation_aspect : None, scalar, optional (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 : scalar, optional (default: 1)
            dpi_cor is currently used for linewidth-related things and shrink
            factor. Mutation scale is affected by this.

        Notes
        -----
        Valid kwargs are:
        %(Patch)s
        Ng      @zZThe "arrow_transmuter" keyword argument is not used, and will be removed in Matplotlib 3.1Úarrow_transmuterzkeyword argument)rž   rÏ  Úobj_typezSThe "connector" keyword argument is not used, and will be removed in Matplotlib 3.1rD  rÂ  z.either posA and posB, or path need to provided)r   r«   r   r'   r¿  Úset_connectionstyler”   r+  r-  r0  r1  rÀ  Úset_arrowstyler  r  Úset_dpi_cor)r<   r5  r6  rI   Ú
arrowstylerÃ  ÚconnectionstylerD  r+  r-  r0  r1  r  r  Údpi_corrB   rC   rC   rD   r'   t  s<    V

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 : scalar
        TN)Ú_dpi_corr|   )r<   rÊ  rC   rC   rD   rÇ  ô  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
        -------
        dpi_cor : scalar
        )rË  )r<   rC   rC   rD   Ú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)r¿  r|   )r<   r5  r6  rC   rC   rD   Úset_positions  s
    


zFancyArrowPatch.set_positionsc             C   s   || _ d| _dS )z™
        Set the tail patch.

        Parameters
        ----------
        patchA : Patch
            :class:`matplotlib.patch.Patch` instance.
        TN)r+  r|   )r<   r+  rC   rC   rD   Ú
set_patchA  s    	zFancyArrowPatch.set_patchAc             C   s   || _ d| _dS )z™
        Set the head patch.

        Parameters
        ----------
        patchB : Patch
            :class:`matplotlib.patch.Patch` instance.
        TN)r-  r|   )r<   r-  rC   rC   rD   Ú
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 : None, ConnectionStyle instance, or string
            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ã  rL   rå  r  Ú
_connectorr|   )r<   rÉ  rÝ  rC   rC   rD   rÅ  3  s    z#FancyArrowPatch.set_connectionstylec             C   s   | j S )z?
        Return the :class:`ConnectionStyle` instance.
        )rÐ  )r<   rC   rC   rD   Úget_connectionstyleQ  s    z#FancyArrowPatch.get_connectionstylec             K   s<   |dkrt jƒ S t|t jƒr$|| _nt |f|Ž| _d| _dS )aO  
        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, ArrowStyle, str, optional (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)ra  rã  rL   rå  Ú_arrow_transmuterr|   )r<   rÈ  rÝ  rC   rC   rD   rÆ  W  s    zFancyArrowPatch.set_arrowstylec             C   s   | j S )z/
        Return the arrowstyle object.
        )rÒ  )r<   rC   rC   rD   Úget_arrowstylet  s    zFancyArrowPatch.get_arrowstylec             C   s   || _ d| _dS )zg
        Set the mutation scale.

        Parameters
        ----------
        scale : scalar
        TN)r  r|   )r<   r'  rC   rC   rD   r   z  s    z"FancyArrowPatch.set_mutation_scalec             C   s   | j S )zd
        Return the mutation scale.

        Returns
        -------
        scale : scalar
        )r  )r<   rC   rC   rD   r!  …  s    z"FancyArrowPatch.get_mutation_scalec             C   s   || _ d| _dS )z{
        Set the aspect ratio of the bbox mutation.

        Parameters
        ----------
        aspect : scalar
        TN)r  r|   )r<   r"  rC   rC   rD   r#  �  s    z#FancyArrowPatch.set_mutation_aspectc             C   s   | j S )z?
        Return the aspect ratio of the bbox mutation.
        )r  )r<   rC   rC   rD   r$  š  s    z#FancyArrowPatch.get_mutation_aspectc             C   s0   | j ƒ \}}tj|ƒrt|ƒ}| 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_displaycoordr]   rg  r   rE   r¢  Útransform_path)r<   r#  rh  rC   rC   rD   rF      s    
zFancyArrowPatch.get_pathc             C   sº   | j ƒ }| jdk	rx| j| jd ƒ}| j| jd ƒ}| jƒ j|ƒ}| jƒ j|ƒ}| jƒ ||| j| j| j| | j	| d�}n| jƒ j
| jƒ}| jƒ || jƒ | | jƒ | | jƒ ƒ\}}||fS )zN
        Return the mutated path of the arrow in display coordinates.
        Nr   r   )r+  r-  r0  r1  )rÌ  r¿  rÅ   rE   r¡  rÑ  r+  r-  r0  r1  rÕ  rÀ  rÓ  r!  rO   r$  )r<   rÊ  r5  r6  r#  rh  rC   rC   rD   rÔ  ­  s$    



z(FancyArrowPatch.get_path_in_displaycoordc             C   s´   | j ƒ sd S tj| ddd��Ž | j|ƒ�x}| j|jdƒƒ | jƒ \}}tj|ƒs\|g}|g}t	j
ƒ }x6t||ƒD ](\}}||||r’| jd r’| jnd ƒ qpW W d Q R X W d Q R X d S )Nr!   )r•   r™   g      ð?rK   )r¸   r   r¹   r·   rÇ  rë   rÔ  r]   rg  r	   rv   r¥  rk   )r<   rµ   r²   rI   rh  r¾   rú  r9  rC   rC   rD   r¿   Í  s    
zFancyArrowPatch.draw)NNNrÁ  NrÂ  NNNr1  r1  r   Nr   )N)rÆ   rÇ   rÈ   rÉ   r~   rÝ   r   ró   r'   rÇ  rÌ  rÍ  rÎ  rÏ  rÅ  rÑ  rÆ  rÓ  r   r!  r#  r$  rF   rÔ  r¿   rC   rC   rC   rD   ri  `  sB   
            s

 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 :class:`~matplotlib.patches.ConnectionPatch` class is to make
    connecting lines between 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)r<   rC   rC   rD   rÝ   ë  s    zConnectionPatch.__str__Nr|  rÂ  ç        ç      $@Fç      ð?c             K   sj   |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 :class:`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,1 is lower left of axes and 1,1 is upper right
        'data'              use the coordinate system of the object being
                            annotated (default)
        'offset points'     Specify an 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`.
        Nr   r   )r5  r6  rÈ  rÃ  rÉ  rD  r+  r-  r0  r1  r  r  Úclip_onrÊ  )r   r   )r   r   )	r×  rØ  Úcoords1Úcoords2ÚaxesAÚaxesBri  r'   Ú_annotation_clip)r<   ZxyAZxyBZcoordsAZcoordsBrß  rà  rÈ  rÃ  rÉ  rD  r+  r-  r0  r1  r  r  rÜ  rÊ  rB   rC   rC   rD   r'   ï  s0    BzConnectionPatch.__init__c             C   s:  |dkr| j }|dkrF|j}t| j|ƒƒ}t| j|ƒƒ}|j||fƒS |dkr¾| j\}}| jdkrp| j||dƒS | j||| jƒ\}}| j	j
ƒ }||d 9 }||d 9 }||7 }||7 }||fS |dk�r|| }	}
|
tj|	ƒ }|
tj|	ƒ }|j}|j||fƒS |dk�rz| j	j}| j	jj\}}}}|| }
|| }||d 9 }||d 9 }|dk �r`|
| }|dk �rr|| }||fS |dk�rÒ| j	jj\}}}}|| }
|| }|dk �r¸|
| }|dk �rÊ|| }||fS |d	k�rò| j	j}|j||fƒS |d
k�r„| j	j}|jj\}}}}|| }
|| }|dk �r@|
|| d  }n||| d  }|dk �rl||| d  }n||| d  }||fS |dk�rî|jj\}}}}|| }
|| }|dk �rÂ|
| }n|| }|dk �rÞ|| }n|| }||fS |dk�r|j}|j||fƒS t|tjƒ�r(|j||fƒS tdj|ƒƒ‚dS )z=
        calculate the pixel position of given point
        NÚdatazoffset pointsg      R@Úpolarzfigure pointsr   zfigure pixelszfigure fractionzaxes pointszaxes pixelszaxes fractionz,{} is not a valid coordinate transformation.)r�  Ú	transDatar…   rÂ   rÃ   r¡  rÄ   Úxycoordsr6  rr  Úget_dpir]   r‘  r’  rs  r  r¯  ZtransFigureÚ	transAxesrL   r	   Ú	Transformr”   rÌ  )r<   rT   rU   r–   r�  rH   rP  rQ  rs  r•  r8  r  r�   rŒ   r  ÚtrC   rC   rD   r6  O  sœ    




















zConnectionPatch._get_xyc             C   s   || _ d| _dS )aM  
        set *annotation_clip* attribute.

          * True: the annotation will only be drawn when self.xy is inside the
                   axes.
          * False: the annotation will always be drawn regardless of its
                    position.
          * None: the self.xy will be checked only if *xycoords* is "data"
        TN)rá  r|   )r<   r�   rC   rC   rD   Úset_annotation_clipº  s    
z#ConnectionPatch.set_annotation_clipc             C   s   | j S )z
        Return *annotation_clip* attribute.
        See :meth:`set_annotation_clip` for the meaning of return values.
        )rá  )r<   rC   rC   rD   Ú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 )zK
        Return the mutated path of the arrow in the display coord
        )r+  r-  r0  r1  )rÌ  r×  r6  rÝ  rß  rØ  rÞ  rà  rÑ  r+  r-  r0  r1  rÓ  r!  rO   r$  )r<   rÊ  rT   rU   r5  r6  r#  rh  rC   rC   rD   rÔ  Î  s     




z(ConnectionPatch.get_path_in_displaycoordc             C   sª   | j ƒ }|s|dkrL| jdkrL| j\}}| j||| j| jƒ}| jj|ƒsLdS |sb|dkr¦| jdkr¦| j\}}| j||| j| j	ƒ}| j	dkr’| j}n| j	}|j|ƒs¦dS dS )z/Check whether the annotation needs to be drawn.Nrâ  FT)
rë  rÝ  r×  r6  rß  r�  rS   rÞ  rØ  rà  )r<   rµ   r�   rT   rU   Úxy_pixelr�  rC   rC   rD   Ú	_check_xyë  s    



zConnectionPatch._check_xyc             C   s8   |d k	r|| _ | jƒ  s$| j|ƒ r(d S tj| |ƒ d S )N)Ú	_rendererr¸   rí  ri  r¿   )r<   rµ   rC   rC   rD   r¿     s
    zConnectionPatch.draw)NNNr|  NrÂ  NNNrÙ  rÙ  rÚ  NFrÛ  )N)rÆ   rÇ   rÈ   rÉ   rÝ   r   ró   r'   r6  rê  rë  rÔ  rí  r¿   rC   rC   rC   rD   rÖ  æ  s.                R
krÖ  )rÏ   rÐ   rÑ   rÒ   rÓ   rÔ   rÕ   rÖ   r×   rØ   rÙ   rÚ   r   )NT)r€  N)r1  )N)IrÌ   r°   rÈ  r~  Únumbersr   rÀ  Únumpyr]   Ú
matplotlibr(   r¹  r   r   r   r   r   rˆ   r	   Zbezierr
   r   r   r   r   r   r   r   r   r   rI   r   Ú_define_aliasesr&   r   ÚkwdocZpatchdocr€  Úinterpdr;   ró   r'   rÛ   rÏ   rÑ   r+  rÒ   rÓ   rÔ   rÕ   rÉ   Ú
deprecatedrÖ   r×   rØ   rÐ   rÙ   r±  r²  rÅ  rÓ  rÕ  r  rÖ  ré  rê  rÛ  rÚ   r'  r`  ra  ri  rÖ  rC   rC   rC   rD   Ú<module>   s     0
    A
 @ *Ya[CceS, e
 

	8   d {   5         	