3
$ßL]!Z  ã               @   sd   d dl Zd dlZd dlmZmZmZ d dlmZ d dlj	Z
d dljZd dljZG dd„ dejƒZdS )é    N)ÚcbookÚ	docstringÚrcParams)Úallow_rasterizationc                   s  e Zd ZdZdd„ Zej‡ fdd„ƒZdd„ Zdd	„ Z	d
d„ Z
dd„ Zdd„ Zdd„ Z‡ fdd„Zd:‡ fdd„	Zdd„ Zdd„ Zdd„ Zdd„ Zejdƒd d!„ ƒZd"d#„ Ze‡ fd$d%„ƒZd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Ze d2d3„ ƒZ!e d4d5„ ƒZ"e d6d7„ ƒZ#d8d9„ Z$‡  Z%S );ÚSpineaÓ  an axis spine -- the line noting the data area boundaries

    Spines are the lines connecting the axis tick marks and noting the
    boundaries of the data area. They can be placed at arbitrary
    positions. See function:`~matplotlib.spines.Spine.set_position`
    for more information.

    The default position is ``('outward',0)``.

    Spines are subclasses of class:`~matplotlib.patches.Patch`, and
    inherit much of their behavior.

    Spines draw a line, a circle, or an arc depending if
    function:`~matplotlib.spines.Spine.set_patch_line`,
    function:`~matplotlib.spines.Spine.set_patch_circle`, or
    function:`~matplotlib.spines.Spine.set_patch_arc` has been called.
    Line-like is the default.

    c             C   s   dS )Nr   © )Úselfr   r   ú9/tmp/pip-install-edjban26/matplotlib/matplotlib/spines.pyÚ__str__   s    zSpine.__str__c                s¸   t ƒ jf |Ž || _| j| jjƒ || _| jdƒ | jtd ƒ | j	td ƒ | j
dƒ d| _| jdƒ | j| jjƒ d| _d| _d| _t|tjjƒsžtdƒ‚|| _d	| _tjƒ | _dS )
zè
        - *axes* : the Axes instance containing the spine
        - *spine_type* : a string specifying the spine type
        - *path* : the path instance used to draw the spine

        Valid kwargs are:
        %(Patch)s
        Únonezaxes.edgecolorzaxes.linewidthZ
projectingNg      @Fz4'path' must be an instance of 'matplotlib.path.Path'Úline)ÚsuperÚ__init__ÚaxesZ
set_figureÚfigureÚ
spine_typeZset_facecolorÚset_edgecolorr   Zset_linewidthZset_capstyleÚaxisZ
set_zorderÚset_transformÚ	transDataÚ_boundsÚ_smart_boundsÚ	_positionÚ
isinstanceÚ
matplotlibÚpathÚPathÚ
ValueErrorÚ_pathÚ_patch_typeÚmtransformsÚIdentityTransformÚ_patch_transform)r   r   r   r   Úkwargs)Ú	__class__r   r	   r   "   s(    



zSpine.__init__c             C   sB   || _ | jdkr | jjj|ƒ n| jdkr8| jjj|ƒ d| _dS )	z7Set the spine and associated axis to have smart bounds.ÚleftÚrightÚtopÚbottomTN)r%   r&   )r'   r(   )r   r   r   ZyaxisÚset_smart_boundsZxaxisÚstale)r   Úvaluer   r   r	   r)   Q   s    

zSpine.set_smart_boundsc             C   s   | j S )z*Return whether the spine has smart bounds.)r   )r   r   r   r	   Úget_smart_bounds\   s    zSpine.get_smart_boundsc             C   sT   d| _ || _|d | _|d | _|| _|| _tjj||ƒ| _	| j
| jjƒ d| _dS )zSet the spine to be arc-like.Úarcé   TN)r   Ú_centerÚ_widthÚ_heightZ_theta1Z_theta2Úmpathr   r-   r   r   r   Ú	transAxesr*   )r   ÚcenterÚradiusÚtheta1Útheta2r   r   r	   Úset_patch_arc`   s    

zSpine.set_patch_arcc             C   s8   d| _ || _|d | _|d | _| j| jjƒ d| _dS )zSet the spine to be circular.Úcircler.   TN)r   r/   r0   r1   r   r   r3   r*   )r   r4   r5   r   r   r	   Úset_patch_circlem   s    

zSpine.set_patch_circlec             C   s   d| _ d| _dS )zSet the spine to be linear.r   TN)r   r*   )r   r   r   r	   Úset_patch_linew   s    zSpine.set_patch_linec             C   sj   | j dkst‚| j| jd ƒ| j| jd ƒf}| j| jƒ}| j| jƒ}tjƒ j	|d |d ƒ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-   r9   r   é   g      à?N)r-   r9   )r   ÚAssertionErrorZconvert_xunitsr/   Zconvert_yunitsr0   r1   r    ÚAffine2DZscaleÚ	translater"   )r   r4   ÚwidthÚheightr   r   r	   Ú_recompute_transform}   s    zSpine._recompute_transformc                s&   | j dkr| jƒ  | jS tƒ jƒ S d S )Nr-   r9   )r-   r9   )r   rB   r"   r   Úget_patch_transform)r   )r$   r   r	   rC   Œ   s    
zSpine.get_patch_transformNc                s–  | j ƒ  tƒ j|d�}| jdkr$|S |g}| jjd g}t| jjƒdkrZ|j| jjd ƒ �x,|D �]"}|jƒ }|j	}|j
}|dkrŽd}	d}
n|dkr d}	d}
nd}	d}
|	| d | jj }	|
| d | jj }
|jjƒ �r&| jdk�r|j|	 |_|j|
 |_n$| jdk�r&|j|	 |_|j|
 |_|jjƒ �r|| jdk�rX|j|	 |_|j|
 |_n$| jdk�r||j|	 |_|j|	 |_|j|ƒ qbW tjj|ƒS )a  
        Return the window extent of the spines in display space, including
        padding for ticks (but not their labels)

        See Also
        --------
        matplotlib.axes.Axes.get_tightbbox
        matplotlib.axes.Axes.get_window_extent

        )ÚrendererNr   r<   ÚoutÚing      à?éH   r%   r(   r&   r'   )r%   )r(   )r&   )r'   )Ú_adjust_locationr   Úget_window_extentr   Z
majorTicksÚlenZ
minorTicksÚappendÚfrozenÚ_sizeZ_tickdirr   ZdpiZ	tick1lineZget_visibler   Zx0Úx1Zy0Úy1Z	tick2liner    ZBboxÚunion)r   rD   ZbbZbboxesZtickstocheckZtickZbb0ZticklZtickdirZpadoutZpadin)r$   r   r	   rI   “   sL    
zSpine.get_window_extentc             C   s   | j S )N)r   )r   r   r   r	   Úget_pathÍ   s    zSpine.get_pathc             C   s    | j d krd| _ | j| j ƒ d S )NÚoutwardç        )rR   rS   )r   Úset_position)r   r   r   r	   Ú_ensure_position_is_setÐ   s    
zSpine._ensure_position_is_setc             C   s$   || _ | j dk	r| j jƒ  d| _dS )zÅRegister an axis.

        An axis should be registered with its corresponding spine from
        the Axes instance. This allows the spine to clear any axis
        properties when needed.
        NT)r   Úclar*   )r   r   r   r   r	   Úregister_axisÖ   s    

zSpine.register_axisc             C   s   d| _ | jdk	r| jjƒ  dS )zClear the current spine.N)r   r   rV   )r   r   r   r	   rV   â   s    
z	Spine.claz3.1c             C   sj   | j ƒ  | j}t|tƒr2|dkr&d}n|dkr2d}t|ƒdkrFtdƒ‚|\}}|d	krb|dkrbd
S dS dS )z·Return True if directly on axes frame.

        This is useful for determining if a spine is the edge of an
        old style MPL plot. If so, this function will return True.
        r4   r   ç      à?ÚzeroÚdatar   r.   zposition should be 2-tuplerR   TFN)r   rX   )rZ   r   )rU   r   r   ÚstrrJ   r   )r   ÚpositionÚposition_typeÚamountr   r   r	   Úis_frame_likeè   s    
zSpine.is_frame_likec             C   s  | j dkrdS | jdk�rh| j dkr4| jjj\}}n(| j dkrN| jjj\}}ntd| j  ƒ‚| j�rrt||gƒ\}}| j dkr˜| jj	j\}}| jj
ƒ }n"| j dkrº| jj	j\}}| jjƒ }tj|ƒ}t||gƒ\}}||k râ|}n:||k||k@ }|| }	t|	ƒ�r|	d }n|}t||ƒ}||k�r,|}n:||k||k@ }|| }	t|	ƒ�rX|	d	 }n|}t||ƒ}n
| j\}}| jd
k�r˜| j dk�rˆy| jjƒ }
W n tk
�r²   d}
Y nX y| jjƒ }W n tk
�rÜ   d	}Y nX ||
 | }||
 | }||k�r
|| }}tjjtj|ƒtj|ƒƒ| _| j dk�r–| jjj\}}y| jjƒ }W n tk
�rh   |}Y nX || ||  }|| _|| _ntd| j  ƒ‚nf| jj}|jdk�s´tdƒ‚| j dk�rÒ||d< ||d< n,| j dk�rð||d< ||d< ntd| j  ƒ‚dS )z4Automatically set spine bounds to the view interval.r9   Nr%   r&   r'   r(   zunknown spine spine_type: %sr<   r   r-   z#unable to set bounds for spine "%s"r.   zunexpected vertices shape)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   ZviewLimZ	intervalyZ	intervalxr   r   ÚsortedZdataLimZ
get_yticksZ
get_xticksÚnpÚsortrJ   ÚmaxÚminr   Zget_theta_directionÚAttributeErrorZget_theta_offsetr2   r   r-   Zrad2degr   Zget_roriginr1   r0   ZverticesÚshaper=   )r   ÚlowÚhighZviewlim_lowZviewlim_highZdatalim_lowZdatalim_highZticksZcondZtickvalsÚ	directionÚoffsetZrminZrmaxZroriginZscaled_diameterZv1r   r   r	   rH   þ   s�    





















zSpine._adjust_locationc                s   | j ƒ  tƒ j|ƒ}d| _|S )NF)rH   r   Údrawr*   )r   rD   Úret)r$   r   r	   rl   j  s    z
Spine.drawc             C   sü  | j ƒ  | j}t|tƒr2|dkr&d}n|dkr2d}t|ƒdksFtdƒ‚|\}}|dksZt‚|d	k� rö|dkr|d
tjƒ f| _nv| j	dkrÔdddddœ| j	 }||d  d }||d  d }dtj
||| jjƒf| _ntjd| j	 ƒ d
tjƒ f| _�n|dk�rt| j	d k�r*dtjjdddd|dƒf| _nH| j	d!k�rTdtjjddddd|ƒf| _ntjd| j	 ƒ d
tjƒ f| _n„|dk�rø| j	d"k�r’|d8 }| j	d#k�r¶dtjƒ j|dƒf| _nB| j	d$k�rÚdtjƒ jd|ƒf| _ntjd| j	 ƒ d
tjƒ f| _dS )%z6Calculate the offset transform performed by the spine.r4   r   ç      à?rY   rZ   r   r.   zposition should be 2-tuplerR   Úidentityr%   r&   r'   r(   r<   )r%   r&   r(   r'   g      R@Úpostz2unknown spine type "%s": no spine offset performedÚpreN)r   rn   )rZ   r   )r   rR   rZ   )r%   r&   r'   r(   r`   )r`   r   )r<   r   r`   )r   r`   )r   r<   )r%   r&   )r(   r'   )r&   r'   )r%   r&   )r(   r'   )rU   r   r   r[   rJ   r=   r    r!   Ú_spine_transformr   ZScaledTranslationr   Zdpi_scale_transr   Z_warn_externalr>   Zfrom_valuesr?   )r   r\   r]   r^   Z
offset_vecZoffset_xZoffset_yr   r   r	   Ú_calc_offset_transformq  sv    







zSpine._calc_offset_transformc             C   sl   |dkr
n(t |ƒdkrtdƒ‚|d dkr2td	ƒ‚|| _| jƒ  | j| jƒ ƒ | jd
k	rb| jjƒ  d| _d
S )aq  Set the position of the spine.

        Spine position is specified by a 2 tuple of (position type,
        amount). The position types are:

        * 'outward' : place the spine out from the data area by the
          specified number of points. (Negative values specify placing the
          spine inward.)

        * 'axes' : place the spine at the specified Axes coordinate (from
          0.0-1.0).

        * 'data' : place the spine at the specified data coordinate.

        Additionally, shorthand notations define a special positions:

        * 'center' -> ('axes',0.5)
        * 'zero' -> ('data', 0.0)

        r4   rY   r.   z&position should be 'center' or 2-tupler   rR   r   rZ   z:position[0] should be one of 'outward', 'axes', or 'data' NT)r4   rY   )rR   r   rZ   )	rJ   r   r   rs   r   Úget_spine_transformr   Zreset_ticksr*   )r   r\   r   r   r	   rT   »  s    

zSpine.set_positionc             C   s   | j ƒ  | jS )zReturn the spine position.)rU   r   )r   r   r   r	   Úget_positionâ  s    zSpine.get_positionc             C   s   | j ƒ  | j\}}|dkr€| jj|| jj | jj  }| jdkrRtj|| jj	ƒ}n*| jdkrntj| jj	|ƒ}nt
d| j ƒ‚|S | jdkrš| jjdd�}n(| jdkr´| jjdd�}nt
d| j ƒ‚|d	krÎ|S |d
krÞ|| S |dk� rð|| S t
d| ƒ‚dS )zReturn the spine transform.rZ   r%   r&   r'   r(   zunknown spine spine_type: %sZgrid)Úwhichro   rp   rq   z unknown spine_transform type: %sN)r%   r&   )r'   r(   )r%   r&   )r'   r(   )rU   rr   r   Z
transScaleZtransLimitsr3   r   r    Zblended_transform_factoryr   r   Zget_yaxis_transformZget_xaxis_transform)r   ÚwhatÚhowZ
data_xformÚresultZbase_transformr   r   r	   rt   ç  s6    







zSpine.get_spine_transformc             C   s&   | j dkrtdƒ‚||f| _d| _dS )zSet the bounds of the spine.r9   z5set_bounds() method incompatible with circular spinesTN)r   r   r   r*   )r   rh   ri   r   r   r	   Ú
set_bounds  s
    

zSpine.set_boundsc             C   s   | j S )zGet the bounds of the spine.)r   )r   r   r   r	   Ú
get_bounds  s    zSpine.get_boundsc             K   s”   |dkrt jd
dgƒ}nT|dkr0t jddgƒ}n<|dkrHt jddgƒ}n$|dkr`t jddgƒ}ntd| ƒ‚| |||f|Ž}|jtd	j|ƒ ƒ |S )zA
        (staticmethod) Returns a linear :class:`Spine`.
        r%   ç        ç+‡ÙÎ÷ï?r&   ç      ð?r(   r'   z"unable to make path for spine "%s"zaxes.spines.{0})r|   r}   )r|   r}   )r~   r}   )r~   r}   )r}   r|   )r}   r|   )r}   r~   )r}   r~   )r2   r   r   Zset_visibler   Úformat)Úclsr   r   r#   r   ry   r   r   r	   Úlinear_spine  s    zSpine.linear_spinec       
      K   s2   t jj||ƒ}| |||f|Ž}	|	j||||ƒ |	S )z>
        (classmethod) Returns an arc :class:`Spine`.
        )r2   r   r-   r8   )
r€   r   r   r4   r5   r6   r7   r#   r   ry   r   r   r	   Ú	arc_spine-  s    zSpine.arc_spinec             K   s.   t jjƒ }d}| |||f|Ž}|j||ƒ |S )zC
        (staticmethod) Returns a circular :class:`Spine`.
        r9   )r2   r   Zunit_circler:   )r€   r   r4   r5   r#   r   r   ry   r   r   r	   Úcircular_spine8  s
    
zSpine.circular_spinec             C   s   | j |ƒ d| _dS )aJ  
        Set the edgecolor.

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

        Notes
        -----
        This method does not modify the facecolor (which defaults to "none"),
        unlike the `Patch.set_color` method defined in the parent class.  Use
        `Patch.set_facecolor` to set the facecolor.
        TN)r   r*   )r   Úcr   r   r	   Ú	set_colorC  s    
zSpine.set_color)N)&Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   Zdedent_interpdr   r)   r,   r8   r:   r;   rB   rC   rI   rQ   rU   rW   rV   r   Ú
deprecatedr_   rH   r   rl   rs   rT   ru   rt   rz   r{   Úclassmethodr�   r‚   rƒ   r…   Ú__classcell__r   r   )r$   r	   r      s8   /
:lJ'%r   )Znumpyrb   r   r   r   r   Zmatplotlib.artistr   Zmatplotlib.transformsZ
transformsr    Zmatplotlib.patchesZpatchesZmpatchesZmatplotlib.pathr   r2   ZPatchr   r   r   r   r	   Ú<module>   s   


