3
ƽhN                 @   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ej	ddd Z
ej	dd	d
 Zdd Zdd Zdd Zdd Z fddZd6 fdd	Zdd Zdd Zdd Zdd Zd d! Ze fd"d#Zd$d% Zd&d' Zd(d) Zd7d*d+Zd,d- Zed.d/ Zed0d1 Z ed2d3 Z!d4d5 Z"  Z#S )8SpineaI  
    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 `~.Spine.set_position` for more information.

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

    Spines are subclasses of `.Patch`, and inherit much of their behavior.

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

    c             C   s   dS )Nr    )selfr   r   7/tmp/pip-build-7iwl8md4/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jtjj|d || _d	| _tj | _dS )
a  
        Parameters
        ----------
        axes : `~matplotlib.axes.Axes`
            The `~.axes.Axes` instance containing the spine.
        spine_type : str
            The spine type.
        path : `~matplotlib.path.Path`
            The `.Path` instance used to draw the spine.

        Other Parameters
        ----------------
        **kwargs
            Valid keyword arguments are:

            %(Patch)s
        nonezaxes.edgecolorzaxes.linewidthZ
projectingNg      @F)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	_positionr   Z_check_isinstance
matplotlibr   Path_path_patch_typemtransformsZIdentityTransform_patch_transform)r   r   r   r   kwargs)	__class__r   r	   r      s$    


zSpine.__init__z3.2c             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&   U   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_boundsa   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_arcf   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,   r-   r.   r   r   r0   r'   )r   r1   r2   r   r   r	   set_patch_circles   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_line}   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!  
        Notes
        -----
        This cannot be called until after this has been added to an Axes,
        otherwise unit conversion will fail. This makes it very important to
        call the accessor method and not directly access the transformation
        member variable.
        r*   r6   r      g      ?N)r*   r6   )r   AssertionErrorZconvert_xunitsr,   Zconvert_yunitsr-   r.   r   Affine2DZscale	translater   )r   r1   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*   r6   )r*   r6   )r   r?   r   r   get_patch_transform)r   )r!   r   r	   r@      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rd}	d}
n|dkrd}	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   r9   outing      ?H   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   rA   ZbbZbboxesZtickstocheckZtickZbb0ZticklZtickdirZpadoutZpadin)r!   r   r	   rF      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        )rO   rP   )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   rS   )r   r   r   r	   rS      s    
z	Spine.clac             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ry| 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st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.r6   Nr"   r#   r$   r%   zunknown spine spine_type: %sr9   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   r9   )r9   r9   )r%   r$   )r   r   )r9   r   ) r   r   r   ZviewLimZ	intervalyZ	intervalx
ValueErrorr   sortedZdataLimZ
get_yticksZ
get_xticksnpsortrG   maxminr   Zget_theta_directionAttributeErrorZget_theta_offsetr/   r   r*   Zrad2degr   Zget_roriginr.   r-   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	   rE      s    





















zSpine._adjust_locationc                s   | j   t j|}d| _|S )NF)rE   r   drawr'   )r   rA   ret)r!   r   r	   rb   \  s    z
Spine.drawc             C   sd   |dkr
n(t |dkrtd|d dkr2td	|| _| j| j  | jd
k	rZ| jj  d| _d
S )aR  
        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 place the spine inwards.)
        * 'axes': place the spine at the specified Axes coordinate (0 to 1).
        * 'data': place the spine at the specified data coordinate.

        Additionally, shorthand notations define a special positions:

        * 'center' -> ('axes', 0.5)
        * 'zero' -> ('data', 0.0)
        r1   zeror+   z&position should be 'center' or 2-tupler   rO   r   dataz:position[0] should be one of 'outward', 'axes', or 'data' NT)r1   rd   )rO   r   re   )rG   rV   r   r   get_spine_transformr   Zreset_ticksr'   )r   positionr   r   r	   rQ   c  s    

zSpine.set_positionc             C   s   | j   | jS )zReturn the spine position.)rR   r   )r   r   r   r	   get_position  s    zSpine.get_positionc             C   s  | j   | j}t|tr2|dkr&d}n|dkr2d}t|dksFtd|\}}tjdd	dg|d
 | jdkr|| j	j
dd}n*| jdkr| j	jdd}ntd| j|d	k r|dkr|S ddddd| j }|tj| d }|tj|| jjf  S n|dkrT| jd kr,tjjdddd|d| S | jd!krtjjddddd|| S n~|dkr| jd"krr|d8 }| jd#krtjtj j|d| j	j | j	jS | jd$krtj| j	jtj jd|| j	j S dS )%zReturn the spine transform.r1   r         ?rd   re   r   r+   zposition should be 2-tuplerO   )position_typer"   r#   Zgrid)whichr$   r%   zunknown spine spine_type: r9   )r"   r#   r%   r$   rD   N)r   ri   )re   r   )r"   r#   )r$   r%   rU   )rU   r   )r9   r   rU   )r   rU   )r   r9   )r"   r#   )r%   r$   )r#   r$   )r"   r#   )r%   r$   )rR   r   
isinstancestrrG   r:   r   Z_check_in_listr   r   Zget_yaxis_transformZget_xaxis_transformrV   rX   arrayr   ZScaledTranslationr   Zdpi_scale_transr;   Zfrom_valuesZblended_transform_factoryr<   r   )r   rg   rj   amountZbase_transformZ
offset_vecZoffset_dotsr   r   r	   rf     s\    






zSpine.get_spine_transformc             C   sh   | j dkrtd|dkr,tj|r,|\}}| j p6d\}}|dkrH|}|dkrT|}||f| _d| _dS )a  
        Set the spine bounds.

        Parameters
        ----------
        low : float or None, optional
            The lower spine bound. Passing *None* leaves the limit unchanged.

            The bounds may also be passed as the tuple (*low*, *high*) as the
            first positional argument.

            .. ACCEPTS: (low: float, high: float)

        high : float or None, optional
            The higher spine bound. Passing *None* leaves the limit unchanged.
        r6   z5set_bounds() method incompatible with circular spinesNT)NN)r   rV   rX   iterable
get_boundsr   r'   )r   r^   r_   Zold_lowZold_highr   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	   rq     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 )z#Create and return a linear `Spine`.r"           +?r#         ?r%   r$   z"unable to make path for spine "%s"zaxes.spines.{0})rs   rt   )rs   rt   )ru   rt   )ru   rt   )rt   rs   )rt   rs   )rt   ru   )rt   ru   )r/   r   rV   Zset_visibler   format)clsr   r   r    r   resultr   r   r	   linear_spine  s    zSpine.linear_spinec       
      K   s2   t jj||}| |||f|}	|	j|||| |	S )z!Create and return an arc `Spine`.)r/   r   r*   r5   )
rw   r   r   r1   r2   r3   r4   r    r   rx   r   r   r	   	arc_spine  s    zSpine.arc_spinec             K   s.   t jj }d}| |||f|}|j|| |S )z%Create and return a circular `Spine`.r6   )r/   r   Zunit_circler7   )rw   r   r1   r2   r    r   r   rx   r   r   r	   circular_spine   s
    
zSpine.circular_spinec             C   s   | j | d| _dS )aL  
        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_color	  s    
zSpine.set_color)N)NN)$__name__
__module____qualname____doc__r
   r   Zdedent_interpdr   r   Z
deprecatedr&   r)   r5   r7   r8   r?   r@   rF   rN   rR   rT   rS   rE   r   rb   rQ   rh   rf   rr   rq   classmethodry   rz   r{   r}   __classcell__r   r   )r!   r	   r      s4   6
8l;
		r   )numpyrX   r   r   r   r   Zmatplotlib.artistr   Zmatplotlib.transformsZ
transformsr   Zmatplotlib.patchesZpatchesZmpatchesZmatplotlib.pathr   r/   ZPatchr   r   r   r   r	   <module>   s   


