a
    >f[.                     @   s~   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mZ d dlmZ d dlmZ G dd deZdZejjed	 dS )
    N)_api
_docstring
transforms)	_AxesBase_TransformedBoundsLocator)Axis)	Transformc                       s   e Zd ZdZd fdd	Zdd ZdddZd fd	d
	Ze	e
jdddddZdd Z fddZdd Zdd Zdd Zdd Z  ZS )SecondaryAxisz4
    General class to hold a Secondary_X/Yaxis.
    Nc                    sJ  t jddg|d || _|| _|| _d| _| jdkrpt j| jjg dfi | | j	| _
ddg| _dd	g| _n:t j| jjg d
fi | | j| _
d	dg| _ddg| _d| _| || | | | jdkr| jn| j	}|t  |d | j| j d | j| j d | jdk r6| 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.
        xy)orientationF)r         ?   -C6?topbottomleftright)r   r   r   r   NnoneTg      ?r   )r   check_in_list
_functions_parent_orientation
_ticks_setsuper__init__Zfigurexaxis_axis_locstringsZ_otherstringsyaxis_parentscaleset_locationset_functionsset_major_locatormtickerZNullLocatorset_ticks_positionspinesset_visible_posset_alignment)selfparentr   location	functions	transformkwargsZ	otheraxis	__class__ m/var/www/staging/api/virtual_environments/venv/lib/python3.9/site-packages/matplotlib/axes/_secondary_axes.pyr      s2    





zSecondaryAxis.__init__c                 C   sx   t j| j|d || jd kr0| 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 : {'top', 'bottom', 'left', 'right'}
            Either 'top' or 'bottom' for orientation='x' or
            'left' or 'right' for orientation='y' axis.
        )alignr   Nr   r   TF)r   r   r   r'   r(   r   r&   Zset_label_position)r+   r5   r3   r3   r4   r*   ;   s    zSecondaryAxis.set_alignmentc                 C   s   t jtjdf|d t|trBt j| j|d |dv r:dnd| _n:t|t	j
rV|| _n&td| jd d	| jd
 d||| _| jdkrd| jddg}|durt| jj|}n&| jddd
g}|durt|| jj}|du r| jj}| t|| 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).

        transform : `.Transform`, optional
            Transform for the location to use. Defaults to
            the parent's ``transAxes``, so locations are normally relative to
            the parent axes.

            .. versionadded:: 3.9
        N)r/   )r-   )r   r   r   g        zlocation must be r   z, r   z, or a float, not r
   g|=)r   Zcheck_isinstancer   r   
isinstancestrr   r   r)   numbersReal
ValueErrorZ_locr   Zblended_transform_factoryr   Z	transAxesZset_axes_locatorr   )r+   r-   r/   Zboundsr3   r3   r4   r"   N   s8    

zSecondaryAxis.set_locationc                    s   |    t | d S N)	_set_limsr   apply_aspect)r+   positionr1   r3   r4   r=      s    zSecondaryAxis.apply_aspectF)minorc                K   s*   | j j||fd|i|}d| _d| _|S )Nr?   T)r   	set_ticksstaler   )r+   tickslabelsr?   r0   retr3   r3   r4   r@      s    zSecondaryAxis.set_ticksc                    s   t  tr6t dkr6t d r6t d r6 | _nDt  trV j fddf| _n$ du rrd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   c                    s      | S r;   )invertedr/   r
   r.   r3   r4   <lambda>       z-SecondaryAxis.set_functions.<locals>.<lambda>Nc                 S   s   | S r;   r3   rG   r3   r3   r4   rI      rJ   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)	r6   tuplelencallabler   r   r/   r:   
_set_scale)r+   r.   r3   rH   r4   r#      s    



zSecondaryAxis.set_functionsc                    s    |    |   t | 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)r<   rN   r   draw)r+   rendererr1   r3   r4   rO      s    	zSecondaryAxis.drawc                 C   s   | j dkr| jj }| j}n| jj }| j}|| jkr>dS | jrN| j	
 }||dkr\dnd| jddd d | jr| j	t| || _dS )z3
        Check if parent has set its scale
        r
   NlogZfunctionlogfunctionr   rH   )r   r   r   Z	get_scaleZ
set_xscaler    Z
set_yscaler!   r   r   Zget_ticklocsr   r$   r%   ZFixedLocator)r+   ZpscaleZ	set_scalerB   r3   r3   r4   rN      s    


zSecondaryAxis._set_scalec                 C   s   | j dkr| j }| j}n| j }| j}|d |d k }| jd t|}|d |d k }||krv|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   Nr   )	r   r   Zget_xlimZset_xlimZget_ylimZset_ylimr   nparray)r+   ZlimsZset_limorderZneworderr3   r3   r4   r<      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)r   Zwarn_external)r+   argsr0   r3   r3   r4   
set_aspect   s    zSecondaryAxis.set_aspectc                 C   sL   | j | j }|j|d | j D ]}|j|u r"|| q"|j| dS )z
        Change the color of the secondary Axes and all decorators.

        Parameters
        ----------
        color : :mpltype:`color`
        )colorsN)Z	_axis_mapr   Zset_tick_paramsr'   valuesaxis	set_colorlabel)r+   colorrZ   Zspiner3   r3   r4   r[     s    
zSecondaryAxis.set_color)N)N)N)N)__name__
__module____qualname____doc__r   r*   r"   r=   r   copyr   r@   r#   rO   rN   r<   rW   r[   __classcell__r3   r3   r1   r4   r	      s   *
@
%r	   a  
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. Both functions must accept
    numpy arrays as input.

    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.

transform : `.Transform`, optional
    If specified, *location* will be
    placed relative to this transform (in the direction of the axis)
    rather than the parent's axis. i.e. a secondary x-axis will
    use the provided y transform and the x transform of the parent.

    .. versionadded:: 3.9

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

Other Parameters
----------------
**kwargs : `~matplotlib.axes.Axes` properties.
    Other miscellaneous Axes parameters.
)_secax_docstring)r8   numpyrS   Z
matplotlibr   r   r   Zmatplotlib.tickerZtickerr%   Zmatplotlib.axes._baser   r   Zmatplotlib.axisr   Zmatplotlib.transformsr   r	   rd   Zinterpdupdater3   r3   r3   r4   <module>   s     
-