o
    iN                     @   sj   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m	Z
 d dlmZ d dlm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	ddd Z
e	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   L/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/matplotlib/spines.py__str__   s   zSpine.__str__c                    s   t  jd
i | || _| | jj || _| d | td  | 	td  | 
d d| _| d | | jj d| _d| _d| _tjtjj|d || _d	| _t | _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.linewidth
projectingNg      @F)pathliner   )super__init__axes
set_figurefigure
spine_typeset_facecolorset_edgecolorr   set_linewidthset_capstyleaxis
set_zorderset_transform	transData_bounds_smart_bounds	_positionr   _check_isinstance
matplotlibr   Path_path_patch_typemtransformsIdentityTransform_patch_transform)r	   r   r   r   kwargs	__class__r   r
   r      s$   


zSpine.__init__z3.2c                 C   sB   || _ | jdv r| jj| n| jdv r| jj| d| _dS )z7Set the spine and associated axis to have smart bounds.leftrighttopbottomTN)r   r   r   yaxisset_smart_boundsxaxisstale)r	   valuer   r   r
   r3   U   s   


zSpine.set_smart_boundsc                 C      | 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 d| _dS )zSet the spine to be arc-like.arc   TN)r%   _center_width_height_theta1_theta2mpathr#   r9   r$   r   r   	transAxesr5   )r	   centerradiustheta1theta2r   r   r
   set_patch_arcf   s   


zSpine.set_patch_arcc                 C   s8   d| _ || _|d | _|d | _| | jj d| _dS )zSet the spine to be circular.circler:   TN)r%   r;   r<   r=   r   r   rA   r5   )r	   rB   rC   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%   r5   r   r   r   r
   set_patch_line}   s   
zSpine.set_patch_linec                 C   sj   | j dv sJ | | jd | | jd f}| | j}| | j}t |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.
        r9   rG   r            ?N)r%   convert_xunitsr;   convert_yunitsr<   r=   r&   Affine2Dscale	translater(   )r	   rB   widthheightr   r   r
   _recompute_transform   s   	
zSpine._recompute_transformc                    s"   | j dv r|   | jS t  S )NrJ   )r%   rT   r(   r   get_patch_transformr   r*   r   r
   rU      s   

zSpine.get_patch_transformNc                    s  |    t j|d}| jdu r|S |g}| jjd g}t| jjdkr-|| jjd  |D ]}| }|j	}|j
}|dkrDd}	d}
n|dkrMd}	d}
nd}	d}
|	| d | jj }	|
| d | jj }
|j r| jd	kr||j|	 |_|j|
 |_n| jd
kr|j|	 |_|j|
 |_|j r| jdkr|j|	 |_|j|
 |_n| jdkr|j|	 |_|j|	 |_|| q/t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   rK   outinrL   H   r-   r1   r.   r0   )_adjust_locationr   get_window_extentr   
majorTickslen
minorTicksappendfrozen_size_tickdirr   dpi	tick1lineget_visibler   x0x1y0y1	tick2liner&   Bboxunion)r	   rV   bbbboxestickstochecktickbb0tickltickdirpadoutpadinr*   r   r
   r[      sL   






zSpine.get_window_extentc                 C   r7   N)r$   r   r   r   r
   get_path   s   zSpine.get_pathc                 C   s$   | j d u rd| _ | | j  d S d S )N)outward        )r    set_positionr   r   r   r
   _ensure_position_is_set   s   
zSpine._ensure_position_is_setc                 C   s$   || _ | j dur| 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   clar5   )r	   r   r   r   r
   register_axis   s   


zSpine.register_axisc                 C   s"   d| _ | jdur| j  dS dS )zClear the current spine.N)r    r   r|   r   r   r   r
   r|      s   
z	Spine.clac                 C   s  | j dkrdS | jdu r| j dv r| jjj\}}n| j dv r&| jjj\}}ntd| j  | jrt||g\}}| j dv rJ| jj	j\}}| j
 }n| j dv r[| jj	j\}}| j }t|}t||g\}}||k ro|}n||k||k@ }|| }	t|	r|	d }n|}t||}||kr|}n"||k||k@ }|| }	t|	r|	d }n|}t||}n| j\}}| jdkrC| j d	v r<z| j }
W n ty   d
}
Y nw z| j }W n ty   d}Y nw ||
 | }||
 | }||kr||}}tjt|t|| _| j dkr:| jjj\}}z| j }W n ty)   |}Y nw || ||  }|| _|| _dS dS td| j  | jj}|jdksQJ d| j dv ra||d< ||d< dS | j d	v rq||d< ||d< dS td| j  )z4Automatically set spine bounds to the view interval.rG   Nr,   r/   zunknown spine spine_type: %sr   r9   r1   r0   rK   r1   z#unable to set bounds for spine "%s")r:   r:   zunexpected vertices shaper   rK   )rK   rK   )r   r   rK   r   )r   r   r   viewLim	intervaly	intervalx
ValueErrorr   sorteddataLim
get_yticks
get_xticksnpsortr]   maxminr%   get_theta_directionAttributeErrorget_theta_offsetr@   r#   r9   rad2degr$   get_roriginr=   r<   verticesshape)r	   lowhighviewlim_lowviewlim_highdatalim_lowdatalim_hightickscondtickvals	directionoffsetrminrmaxroriginscaled_diameterv1r   r   r
   rZ      s   














zSpine._adjust_locationc                    s   |    t |}d| _|S )NF)rZ   r   drawr5   )r	   rV   retr*   r   r
   r   \  s   z
Spine.drawc                 C   sd   |dv rnt |dkrtd|d dvrtd|| _| |   | jdur-| 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)
        )rB   zeror:   z&position should be 'center' or 2-tupler   )rx   r   dataz:position[0] should be one of 'outward', 'axes', or 'data' NT)r]   r   r    r   get_spine_transformr   reset_ticksr5   )r	   positionr   r   r
   rz   c  s   


zSpine.set_positionc                 C   s   |    | jS )zReturn the spine position.)r{   r    r   r   r   r
   get_position  s   zSpine.get_positionc                 C   s  |    | j}t|tr|dkrd}n|dkrd}t|dks#J d|\}}tjg d|d | jd	v r=| jj	d
d}n| jdv rJ| jj
d
d}ntd| j|dkr}|dkr\|S ddddd| j }|t| d }|tjg || jjR   S |dkr| jd	v rtjdddd|d| S | jdv rtjddddd|| S dS |dkr| jdv r|d8 }| jd	v rtt |d| jj | jjS | jdv rt| jjt d|| jj S dS dS )zReturn the spine transform.rB   )r   rL   r   )r   r   r:   zposition should be 2-tuple)r   rx   r   )position_typer,   grid)whichr/   zunknown spine spine_type: rx   r   )r~   r   r   )r   r~   r   )r-   r.   r1   r0   rY   r   rK   r   r   )r.   r0   N)r{   r    
isinstancestrr]   r   _check_in_listr   r   get_yaxis_transformget_xaxis_transformr   r   arrayr&   ScaledTranslationr   dpi_scale_transrO   from_valuesblended_transform_factoryrQ   r   )r	   r   r   amountbase_transform
offset_vecoffset_dotsr   r   r
   r     s|   








zSpine.get_spine_transformc                 C   sh   | j dkr	td|du rt|r|\}}|  pd\}}|du r$|}|du r*|}||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.
        rG   z5set_bounds() method incompatible with circular spinesNNNT)r   r   r   iterable
get_boundsr   r5   )r	   r   r   old_lowold_highr   r   r
   
set_bounds  s   


zSpine.set_boundsc                 C   r7   )zGet the bounds of the spine.)r   r   r   r   r
   r     s   zSpine.get_boundsc                 K   s   |dkrt ddg}n*|dkrt ddg}n|dkr$t ddg}n|dkr0t ddg}ntd	| | |||fi |}|td
|  |S )z#Create and return a linear `Spine`.r-   )ry   +?r.   )      ?r   r1   )r   ry   r0   )r   r   z"unable to make path for spine "%s"zaxes.spines.{0})r@   r#   r   set_visibler   format)clsr   r   r)   r   resultr   r   r
   linear_spine  s   zSpine.linear_spinec           
      K   s6   t j||}| |||fi |}	|	|||| |	S )z!Create and return an arc `Spine`.)r@   r#   r9   rF   )
r   r   r   rB   rC   rD   rE   r)   r   r   r   r   r
   	arc_spine  s   zSpine.arc_spinec                 K   s2   t j }d}| |||fi |}||| |S )z%Create and return a circular `Spine`.rG   )r@   r#   unit_circlerH   )r   r   rB   rC   r)   r   r   r   r   r   r
   circular_spine   s
   
zSpine.circular_spinec                 C   s   |  | 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   r5   )r	   cr   r   r
   	set_color	  s   

zSpine.set_colorrv   r   )$__name__
__module____qualname____doc__r   r   dedent_interpdr   r   
deprecatedr3   r8   rF   rH   rI   rT   rU   r[   rw   r{   r}   r|   rZ   r   r   rz   r   r   r   r   classmethodr   r   r   r   __classcell__r   r   r*   r
   r      sD    5


8l
;


r   )numpyr   r"   r   r   r   matplotlib.artistr   matplotlib.transforms
transformsr&   matplotlib.patchespatchesmpatchesmatplotlib.pathr   r@   Patchr   r   r   r   r
   <module>   s    