3
$ßL]r=  ã               @   sÄ   d dl Z d dlZd dlZd dlZd dljZd dljZ	d dl
jZd dljZd dljZd dlmZ d dlmZmZmZmZmZmZmZmZ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)Ú	_AxesBase)	ÚAutoLocatorÚAutoMinorLocatorÚFixedLocatorÚFuncFormatterÚLogFormatterSciNotationÚ
LogLocatorÚNullLocatorÚNullFormatterÚScalarFormatter)ÚLog10Transformc                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jjƒ }t j||ƒ}|S )N)ÚmtransformsZTransformedBboxZ	transAxesÚfigureZtransFigureÚinverted)ZaxÚrendererÚbbÚtr)Ú_rectÚparent© úG/tmp/pip-install-edjban26/matplotlib/matplotlib/axes/_secondary_axes.pyÚsecondary_locator.   s    z2_make_secondary_locator.<locals>.secondary_locator)r   ÚBboxZfrom_bounds)Zrectr   r   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d"dd„Zdd„ Z	d#‡ fdd„	Z
dd„ Zdd„ Zd$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                sf  || _ || _|| _d| _| jdkr^tƒ j| jjddddgf|Ž | j| _ddg| _	d	d
g| _
nD| jdkr¢tƒ j| jjddddgf|Ž | j| _d
d	g| _	ddg| _
d| _d| _| j|ƒ | j|ƒ | jdkrÔ| j}n| j}|jtjƒ ƒ |jdƒ x| j
D ]}| j| jdƒ qúW x | j	D ]}| j| jdƒ �qW | jdk �rR| j	ddd… | _	| j| 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Úxr   g      ð?é   g-Cëâ6?ÚtopÚbottomÚleftÚrightÚyNÚnoneTg      à?éÿÿÿÿ)Ú
_functionsÚ_parentÚ_orientationÚ
_ticks_setÚsuperÚ__init__r   ÚxaxisÚ_axisÚ_locstringsZ_otherstringsÚyaxisZ
_layoutboxZ_poslayoutboxÚset_locationÚset_functionsÚset_major_locatorÚmtickerr	   Úset_ticks_positionÚspinesÚset_visibleÚ_posÚset_alignment)Úselfr   ZorientationÚlocationÚ	functionsÚkwargsZ	otheraxisÚst)Ú	__class__r   r   r)   >   s<    








zSecondaryAxis.__init__c             C   s    || j krœ|| j d kr,| j ddd… | _ n,|| j d krXtdj|| j d | j d ƒƒ‚| j| j d  jdƒ | j| j d  jdƒ | jj|ƒ | 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 :: string
            either 'top' or 'bottom' for orientation='x' or
            'left' or 'right' for orientation='y' axis

        r   Nr   zW"{}" is not a valid axis orientation, not changing the orientation;choose "{}" or "{}""TFr#   )r,   Ú
ValueErrorÚformatr3   r4   r+   r2   Zset_label_position)r7   Zalignr   r   r   r6   o   s    
zSecondaryAxis.set_alignmentc             C   s˜   t |tƒrJ|dkrd| _qP|dkr*d| _qPtdj|| jd | jd	 ƒƒ‚n|| _|| _| jd
krpd| jddg}n| jddd	g}t|| j	ƒ}| j
|ƒ dS )a   
        Set the vertical or horizontal location of the axes in
        parent-normalized co-ordinates.

        Parameters
        ----------
        location : string or scalar
            The position to put the secondary axis.  Strings can be 'top' or
            'bottom' for orientation='x' and 'right' or 'left' for
            orientation='y', scalar can be a float indicating 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    g      ð?r   r   g        z1location must be '{}', '{}', or a float, not '{}'r   r   r   g»½×Ùß|Û=N)r   r    )r   r   )Ú
isinstanceÚstrr5   r=   r>   r,   Z_locr&   r   r%   Zset_axes_locator)r7   r8   Zboundsr   r   r   r   r.   ‰   s    

zSecondaryAxis.set_locationNc                s   | j ƒ  tƒ j|ƒ d S )N)Ú	_set_limsr(   Úapply_aspect)r7   Úposition)r<   r   r   rB   ³   s    zSecondaryAxis.apply_aspectFc             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, optional
            If ``False`` sets major ticks, if ``True`` sets minor ticks.
            Default is ``False``.
        )ÚminorT)r+   Ú	set_ticksÚstaler'   )r7   ÚticksrD   Úretr   r   r   rE   ·   s    zSecondaryAxis.set_ticksc             C   s´   | j dkr| j}| jjƒ }n| j}| jjƒ }|dkr:d}nd}t|tƒrtt|ƒdkrtt	|d ƒrtt	|d ƒrt|| _
n$|dkr�d	d
„ d	d
„ f| _
ntdƒ‚||| j
ddd… 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   ÚlogÚfunctionlogÚfunctioné   r   r   Nc             S   s   | S )Nr   )r   r   r   r   Ú<lambda>ð   s    z-SecondaryAxis.set_functions.<locals>.<lambda>z›functions 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)r9   r#   )r&   Ú
set_xscaler%   Z
get_xscaleÚ
set_yscaleZ
get_yscaler?   ÚtupleÚlenÚcallabler$   r=   )r7   r9   Ú	set_scaleZparent_scaleÚdefscaler   r   r   r/   É   s    

zSecondaryAxis.set_functionsc                s$   | j ƒ  | jƒ  tƒ j||d� dS )a   
        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.)

        )r   ÚinframeN)rA   Ú
_set_scaler(   Údraw)r7   r   rU   )r<   r   r   rW   ù   s    zSecondaryAxis.drawc             C   sŒ   | j dkr| jjjƒ }| j}| j dkr8| jjjƒ }| j}|dkrFd}nd}| jrZ| jj	ƒ }||| j
ddd	… d� | jrˆ| jjt|ƒƒ dS )
z3
        Check if parent has set its scale
        r   r!   rI   rJ   rK   Nr   )r9   r#   )r&   r%   r*   Z	get_scalerN   r-   rO   r'   r+   Zget_ticklocsr$   r0   r   )r7   ZpscalerS   rT   rG   r   r   r   rV   	  s    


zSecondaryAxis._set_scalec             C   sž   | j dkr$| jjƒ }| j}| jjƒ }| j dkrH| jjƒ }| j}| jjƒ }|d |d k }| j	d t
j|ƒƒ}|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%   Zget_xlimZset_xlimr*   Zget_transformZget_ylimZset_ylimr-   r$   ÚnpÚarray)r7   ZlimsZset_limZtransÚorderZneworderr   r   r   rA   $  s    





zSecondaryAxis._set_limsTc             C   s¢   g }| j ƒ sdS | jƒ  | jƒ }|r>|r>|| |ƒ}| j|ƒ n| jƒ  | jdkr^| jj|ƒ}n| jj|ƒ}|rx|j|ƒ |j| j	|ƒƒ t
jjdd„ |D ƒƒ}|S )a¬  
        Return the tight bounding box of the axes.
        The dimension of the Bbox in canvas coordinate.

        If *call_axes_locator* is *False*, it does not call the
        _axes_locator attribute, which is necessary to get the correct
        bounding box. ``call_axes_locator==False`` can be used if the
        caller is only intereted in the relative size of the tightbbox
        compared to the axes bbox.
        Nr   c             S   s$   g | ]}|j d ks|jd kr|‘qS )r   )ÚwidthÚheight)Ú.0Úbr   r   r   ú
<listcomp>[  s    z/SecondaryAxis.get_tightbbox.<locals>.<listcomp>)Zget_visiblerA   Zget_axes_locatorrB   r&   r*   Úget_tightbboxr-   ÚappendZget_window_extentr   r   Úunion)r7   r   Zcall_axes_locatorr   ÚlocatorÚposZbb_axisZ_bboxr   r   r   r`   9  s$    


zSecondaryAxis.get_tightbboxc             O   s   t j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)ÚcbookZ_warn_external)r7   Úargsr:   r   r   r   Ú
set_aspect_  s    zSecondaryAxis.set_aspectc             K   s"   |dk	r|| j _| j j||f|ŽS )a  
        Set the label for the x-axis.

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

        labelpad : scalar, optional, default: None
            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 : for information on how override and the optional args work
        N)r*   ÚlabelpadÚset_label_text)r7   ZxlabelÚfontdictrh   r:   r   r   r   Ú
set_xlabelf  s    zSecondaryAxis.set_xlabelc             K   s"   |dk	r|| j _| j j||f|ŽS )a  
        Set the label for the x-axis.

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

        labelpad : scalar, optional, default: None
            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 : for information on how override and the optional args work
        N)r-   rh   ri   )r7   Zylabelrj   rh   r:   r   r   r   Ú
set_ylabel  s    zSecondaryAxis.set_ylabelc             C   sˆ   | j dkrH| jd|d� | jd j|ƒ | jd j|ƒ | jjj|ƒ n<| jd|d� | jd j|ƒ | jd j|ƒ | jjj|ƒ dS )	z’
        Change the color of the secondary axes and all decorators
        Parameters
        ----------
        color : Matplotlib color
        r   )ZaxisÚcolorsr   r   r!   r   r    N)r&   Ztick_paramsr3   Ú	set_colorr*   Úlabelr-   )r7   Úcolorr   r   r   rn   ˜  s    
zSecondaryAxis.set_color)N)F)NF)T)NN)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r)   r6   r.   rB   rE   r/   rW   rV   rA   r`   rg   rk   rl   rn   Ú__classcell__r   r   )r<   r   r   9   s   1*
0
&

r   a^  
Warnings
--------

This method is experimental as of 3.1, and the API may change.

Parameters
----------
location : string or scalar
    The position to put the secondary axis.  Strings can be 'top' or
    'bottom', for x-oriented axises or 'left' or 'right' for y-oriented axises
    or a scalar can be a float indicating the relative position
    on the axes to put the new axes (0 being the bottom (left), and 1.0 being
    the top (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.


Other Parameters
----------------
**kwargs : `~matplotlib.axes.Axes` properties.
    Other miscellaneous axes parameters.

Returns
-------
ax : axes._secondary_axes.SecondaryAxis
)Ú_secax_docstring)#ÚcollectionsZnumpyrX   ZnumbersÚwarningsZmatplotlib.docstringZ	docstringZmatplotlib.tickerZtickerr1   Zmatplotlib.transformsZ
transformsr   Zmatplotlib.scaleZscaleZmscaleZmatplotlib.cbookre   Zmatplotlib.axes._baser   r   r   r   r   r   r   r	   r
   r   r   r   r   rv   ZinterpdÚupdater   r   r   r   Ú<module>   s$   




,   