
    G8c|)                         d dl Zd dlmZmZ d dlmZ d dlm	Z	m
Z
 d dlmZ  G d de	      ZdZej                  j!                  e       y)	    N)_api
_docstring)	_AxesBase_TransformedBoundsLocator)Axisc                        e Zd ZdZ fdZd Zd Zd fd	Z ej                  e
j                        dddd       Zd	 Z fd
Zd Zd Zd Zd Z xZS )SecondaryAxisz4
    General class to hold a Secondary_X/Yaxis.
    c                    || _         || _        || _        d| _        | j                  dk(  rKt	        |   | j                  j                  g dfi | | j                  | _        ddg| _	        ddg| _
        nY| j                  dk(  rJt	        |   | j                  j                  g d	fi | | j                  | _        ddg| _	        ddg| _
        d
| _        | j                  |       | j                  |       | j                  dk(  r| j                  }n| j                  }|j                  t!        j"                                |j%                  d       | j&                  | j                     j)                  d       | j&                  | j                     j)                  d       | j*                  dk  r| j                  d
d
d   | _	        | j-                  | j                  d          y
)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__figurexaxis_axis_locstrings_otherstringsyaxis_parentscaleset_locationset_functionsset_major_locatormtickerNullLocatorset_ticks_positionspinesset_visible_posset_alignment)selfparentorientationlocation	functionskwargs	otheraxis	__class__s          A/usr/lib/python3/dist-packages/matplotlib/axes/_secondary_axes.pyr   zSecondaryAxis.__init__   s    $'#GT\\002DOODJ %x0D"('!2D#%GT\\002DOODJ '0D"'!2D  	(#9% #

I

I##G$7$7$9:$$V,D&&'33E:D$$%11$799s?#//"5D4++A./    c                    t        j                  | j                  |       || j                  d   k(  r| j                  ddd   | _        | j                  | j                  d      j	                  d       | j                  | j                  d      j	                  d       | j
                  j                  |       | j
                  j                  |       y)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)r   check_in_listr   r)   r*   r   r(   set_label_position)r-   r8   s     r5   r,   zSecondaryAxis.set_alignment;   s     	4++59D$$Q''#//"5DD$$Q'(44T:D$$Q'(44U;

%%e,

%%e,r6   c                    t        |t              rF|dv rd| _        nA|dv rd| _        n5t        d| j                  d   d| j                  d   d	|      || _        || _        | j                  d
k(  rd| j                  ddg}n| j                  dddg}| j                  t        || j                  j                               y)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   set_axes_locatorr   r   	transAxes)r-   r0   boundss      r5   r#   zSecondaryAxis.set_locationN   s      h$++	//	 '(8(8(;'>b''*--?|MN N !DI	# B.FiiE1-F 	%fdll.D.DE	Gr6   c                 D    | j                          t        | 	  |       y N)	_set_limsr   apply_aspect)r-   positionr4   s     r5   rF   zSecondaryAxis.apply_aspecty   s    X&r6   F)minorc                b     | j                   j                  ||fd|i|}d| _        d| _        |S )NrH   T)r   	set_ticksstaler   )r-   tickslabelsrH   r2   rets         r5   rJ   zSecondaryAxis.set_ticks~   s7    "djj""5&HHH

r6   c                     t        |t              r2t        |      dk(  r$t        |d         rt        |d         r|| _        n|d d f| _        nt        d      | j                          y)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 rD    r   s    r5   <lambda>z-SecondaryAxis.set_functions.<locals>.<lambda>   s     r6   c                     | S rD   rR   rS   s    r5   rT   z-SecondaryAxis.set_functions.<locals>.<lambda>   s    a r6   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)r<   tuplelencallabler   r>   
_set_scale)r-   r1   s     r5   r$   zSecondaryAxis.set_functions   sl    " y%(S^q-@1&8IaL+A (DO*K8DO @ A A 	r6   c                 d    | j                          | j                          t        |   |i | y)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)rE   rY   r   draw)r-   argsr2   r4   s      r5   r[   zSecondaryAxis.draw   s*     	d%f%r6   c                 6   | j                   dk(  r0| j                  j                  j                         }| j                  }| j                   dk(  r0| j                  j
                  j                         }| j                  }| j                  k(  ry|dk(  rd}nd}| j                  r| j                  j                         } || j                  ddd          | j                  r.| j                  j                  t        j                               || _        y)	z3
        Check if parent has set its scale
        r   r   Nlogfunctionlogfunctionr   )r1   )r   r   r   	get_scale
set_xscaler!   
set_yscaler"   r   r   get_ticklocsr   r%   r&   FixedLocator)r-   pscale	set_scaledefscalerL   s        r5   rY   zSecondaryAxis._set_scale   s    
 #\\''113FI#\\''113FIT&&&U?$H!H??JJ++-E 	(doodd&;< ??JJ(()=)=e)DE #r6   c                 ~   | j                   dk(  r&| j                  j                         }| j                  }| j                   dk(  r&| j                  j	                         }| j
                  }d   |d   k  } | j                  d   t        j                  |            }|d   |d   k  }||k7  r|ddd   } |       y)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neworders        r5   rE   zSecondaryAxis._set_lims   s    
 #<<((*DmmG#<<((*DmmGQ$q'!!tq!"((4.17T!W$u":Dr6   c                 .    t        j                  d       y)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   warn_external)r-   r\   r2   s      r5   
set_aspectzSecondaryAxis.set_aspect   s    
 	FGr6   c                 ,   | j                   dk(  r| j                  d|       | j                  j                  j	                  |       | j                  j
                  j	                  |       | j                  j                  j	                  |       y| j                  d|       | j                  j                  j	                  |       | j                  j                  j	                  |       | j                  j                  j	                  |       y)z
        Change the color of the secondary axes and all decorators.

        Parameters
        ----------
        color : color
        r   )axiscolorsr   N)r   tick_paramsr)   r   	set_colorr   r   labelr   r   r!   )r-   colors     r5   r{   zSecondaryAxis.set_color   s     ##e4KK((/KKOO%%e,JJ&&u-#e4KK&&u-KK''.JJ&&u-r6   rD   )__name__
__module____qualname____doc__r   r,   r#   rF   r   copyr   rJ   r$   r[   rY   rE   rv   r{   __classcell__)r4   s   @r5   r	   r	   	   sj    +0Z-&)GV'
 Z__T^^$U  %B&#B&H.r6   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.

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

Other Parameters
----------------
**kwargs : `~matplotlib.axes.Axes` properties.
    Other miscellaneous axes parameters.
)_secax_docstring)numpyrn   
matplotlibr   r   matplotlib.tickertickerr&   matplotlib.axes._baser   r   matplotlib.axisr   r	   r   interpdupdaterR   r6   r5   <module>r      sF     ' # F  w.I w.t$ J     +;  <r6   