o
    i04                     @   sr   d dl Zd dlmZ d dlmZ d dlmZ d dl	m
Z d dlmZ dd ZG dd deZdZejjed dS )	    N)	_AxesBasec                    s   t jj|    fdd}|S )a   
    Helper function to locate the secondary axes.

    A locator gets used in `Axes.set_aspect` to override the default
    locations...  It is a function that takes an axes object and
    a renderer and tells `set_aspect` where it is to be placed.

    This locator make the transform be in axes-relative co-coordinates
    because that is how we specify the "location" of the secondary axes.

    Here *rect* is a rectangle [l, b, w, h] that specifies the
    location for the axes in the transform given by *trans* on the
    *parent*.
    c                    s*   t  j}jj }t ||}|S N)mtransformsTransformedBbox	transAxesfiguretransFigureinverted)axrendererbbtr_rectparent Z/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/matplotlib/axes/_secondary_axes.pysecondary_locator   s   z2_make_secondary_locator.<locals>.secondary_locator)r   Bboxfrom_bounds)rectr   r   r   r   r   _make_secondary_locator
   s   r   c                       s   e Zd ZdZ fddZdd Zdd Zd  fd	d
	Ze	ddd!ddZ
dd Z fddZdd Zdd Zdd Zd"ddZd"ddZdd Z  ZS )#SecondaryAxisz4
    General class to hold a Secondary_X/Yaxis.
    c                    s`  || _ || _|| _d| _| jdkr/t j| jjg dfi | | j| _ddg| _	ddg| _
n"| jdkrQt j| jjg d	fi | | j| _ddg| _	ddg| _
d
| _d
| _d
| _| | | | | jdkrm| j}n| j}|t  |d | j
D ]
}| j| d q| j	D ]
}| j| d q| jdk r| j	d
d
d | _	| | j	d  d
S )z
        See `.secondary_xaxis` and `.secondary_yaxis` for the doc string.
        While there is no need for this to be private, it should really be
        called by those higher level functions.
        Fx)r         ?   -C6?topbottomleftrighty)r   r   r   r   NnoneTg      ?r   )
_functions_parent_orientation
_ticks_setsuper__init__r   xaxis_axis_locstrings_otherstringsyaxis_parentscale
_layoutbox_poslayoutboxset_locationset_functionsset_major_locatormtickerNullLocatorset_ticks_positionspinesset_visible_posset_alignment)selfr   orientationlocation	functionskwargs	otheraxisst	__class__r   r   r)   *   s>   











zSecondaryAxis.__init__c                 C   sx   t j| j|d || jd kr| jddd | _| j| jd  d | j| jd  d | j| | j| dS )a  
        Set if axes spine and labels are drawn at top or bottom (or left/right)
        of the axes.

        Parameters
        ----------
        align : str
            either 'top' or 'bottom' for orientation='x' or
            'left' or 'right' for orientation='y' axis.
        )alignr   Nr#   r   TF)cbook_check_in_listr,   r8   r9   r+   r7   set_label_position)r<   rE   r   r   r   r;   [   s   zSecondaryAxis.set_alignmentc                 C   s   t |tr(|dv rd| _n|dv rd| _ntd| jd d| jd d	||| _|| _| jd
kr;d| jddg}n| jdddg}t|| j}| 	| dS )a+  
        Set the vertical or horizontal location of the axes in
        parent-normalized coordinates.

        Parameters
        ----------
        location : {'top', 'bottom', 'left', 'right'} or float
            The position to put the secondary axis.  Strings can be 'top' or
            'bottom' for orientation='x' and 'right' or 'left' for
            orientation='y'. A float indicates the relative position on the
            parent axes to put the new axes, 0.0 being the bottom (or left)
            and 1.0 being the top (or right).
        )r   r    r   )r   r   g        zlocation must be r   z, r   z, or a float, not r   g|=N)

isinstancestrr:   
ValueErrorr,   _locr&   r   r%   set_axes_locator)r<   r>   boundsr   r   r   r   r2   n   s&   

zSecondaryAxis.set_locationNc                    s   |    t | d S r   )	_set_limsr(   apply_aspect)r<   positionrC   r   r   rP      s   zSecondaryAxis.apply_aspectz3.2minorFc                 C   s    | j j||d}d| _d| _|S )a  
        Set the x ticks with list of *ticks*

        Parameters
        ----------
        ticks : list
            List of x-axis tick locations.
        minor : bool, default: False
            If ``False`` sets major ticks, if ``True`` sets minor ticks.
        )rR   T)r+   	set_ticksstaler'   )r<   ticksrR   retr   r   r   rS      s   zSecondaryAxis.set_ticksc                 C   sf   t |trt|dkrt|d rt|d r|| _n|du r)dd dd f| _ntd|   dS )a&  
        Set how the secondary axis converts limits from the parent axes.

        Parameters
        ----------
        functions : 2-tuple of func, or `Transform` with an inverse.
            Transform between the parent axis values and the secondary axis
            values.

            If supplied as a 2-tuple of functions, the first function is
            the forward transform function and the second is the inverse
            transform.

            If a transform is supplied, then the transform must have an
            inverse.
           r   r   Nc                 S   s   | S r   r   )r   r   r   r   <lambda>   s    z-SecondaryAxis.set_functions.<locals>.<lambda>zfunctions argument of secondary axes must be a two-tuple of callable functions with the first function being the transform and the second being the inverse)rI   tuplelencallabler$   rK   
_set_scale)r<   r?   r   r   r   r3      s   

zSecondaryAxis.set_functionsc                    s&   |    |   t j|i | dS )z
        Draw the secondary axes.

        Consults the parent axes for its limits and converts them
        using the converter specified by
        `~.axes._secondary_axes.set_functions` (or *functions*
        parameter when axes initialized.)
        N)rO   r\   r(   drawr<   argsr@   rC   r   r   r]      s   	zSecondaryAxis.drawc                 C   s   | j dkr| jj }| j}| j dkr| jj }| j}|| jkr#dS |dkr*d}nd}| jr4| j	
 }||| jddd d | jrL| j	t| || _dS )	z3
        Check if parent has set its scale
        r   r!   Nlogfunctionlogfunctionr#   )r?   )r&   r%   r*   	get_scale
set_xscaler.   
set_yscaler/   r'   r+   get_ticklocsr$   r4   r5   FixedLocator)r<   pscale	set_scaledefscalerU   r   r   r   r\      s"   




zSecondaryAxis._set_scalec                 C   s   | j dkr| j }| j}| j dkr| j }| j}|d |d k }| jd t|}|d |d k }||kr?|ddd }|| dS )z
        Set the limits based on parent limits and the convert method
        between the parent and this secondary axes.
        r   r!   r   r   Nr#   )	r&   r%   get_xlimset_xlimget_ylimset_ylimr$   nparray)r<   limsset_limorderneworderr   r   r   rO      s   



zSecondaryAxis._set_limsc                 O   s   t d dS )zj
        Secondary axes cannot set the aspect ratio, so calling this just
        sets a warning.
        z)Secondary axes can't set the aspect ratioN)rF   _warn_externalr^   r   r   r   
set_aspect  s   zSecondaryAxis.set_aspectc                 K   &   |dur|| j _| j j||fi |S )a  
        Set the label for the x-axis.

        Parameters
        ----------
        xlabel : str
            The label text.

        labelpad : float, default: ``self.xaxis.labelpad``
            Spacing in points between the label and the x-axis.

        Other Parameters
        ----------------
        **kwargs : `.Text` properties
            `.Text` properties control the appearance of the label.

        See Also
        --------
        text : Documents the properties supported by `.Text`.
        N)r*   labelpadset_label_text)r<   xlabelfontdictrx   r@   r   r   r   
set_xlabel     zSecondaryAxis.set_xlabelc                 K   rw   )a  
        Set the label for the y-axis.

        Parameters
        ----------
        ylabel : str
            The label text.

        labelpad : float, default: ``self.yaxis.labelpad``
            Spacing in points between the label and the y-axis.

        Other Parameters
        ----------------
        **kwargs : `.Text` properties
            `.Text` properties control the appearance of the label.

        See Also
        --------
        text : Documents the properties supported by `.Text`.
        N)r.   rx   ry   )r<   ylabelr{   rx   r@   r   r   r   
set_ylabel1  r}   zSecondaryAxis.set_ylabelc                 C   s   | j dkr%| jd|d | jd | | jd | | jj| dS | jd|d | jd | | jd | | jj| dS )	z
        Change the color of the secondary axes and all decorators.

        Parameters
        ----------
        color : color
        r   )axiscolorsr   r   r!   r   r    N)r&   tick_paramsr8   	set_colorr*   labelr.   )r<   colorr   r   r   r   J  s   
zSecondaryAxis.set_colorr   )F)NN)__name__
__module____qualname____doc__r)   r;   r2   rP   rF   _make_keyword_onlyrS   r3   r]   r\   rO   rv   r|   r   r   __classcell__r   r   rC   r   r   %   s     1*
!!

r   ao  
Warnings
--------
This method is experimental as of 3.1, and the API may change.

Parameters
----------
location : {'top', 'bottom', 'left', 'right'} or float
    The position to put the secondary axis.  Strings can be 'top' or
    'bottom' for orientation='x' and 'right' or 'left' for
    orientation='y'. A float indicates the relative position on the
    parent axes to put the new axes, 0.0 being the bottom (or left)
    and 1.0 being the top (or right).

functions : 2-tuple of func, or Transform with an inverse

    If a 2-tuple of functions, the user specifies the transform
    function and its inverse.  i.e.
    ``functions=(lambda x: 2 / x, lambda x: 2 / x)`` would be an
    reciprocal transform with a factor of 2.

    The user can also directly supply a subclass of
    `.transforms.Transform` so long as it has an inverse.

    See :doc:`/gallery/subplots_axes_and_figures/secondary_axis`
    for examples of making these conversions.

Returns
-------
ax : axes._secondary_axes.SecondaryAxis

Other Parameters
----------------
**kwargs : `~matplotlib.axes.Axes` properties.
    Other miscellaneous axes parameters.
)_secax_docstring)numpyro   matplotlib.cbookrF   matplotlib.docstring	docstringmatplotlib.tickertickerr5   matplotlib.transforms
transformsr   matplotlib.axes._baser   r   r   r   interpdupdater   r   r   r   <module>   s      ;$