B
    d0T                 @   s  d Z ddlZddlZddlZddlmZ ddlZddlmZm	Z	 ddl
mZmZmZmZmZmZmZmZmZmZ ddlmZmZ G dd dZG d	d
 d
eZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZ G dd deZ!G dd deZ"G dd deZ#G dd  d eZ$G d!d" d"eZ%eee"e%eed#Z&d$d% Z'd&d' Z(e(j re(j d(d))e*e+e' i e(_ d*d+ Z,d,d- Z-e	j.j/d.d))d/d0 e' D  e- 0 d1 dS )2a  
Scales define the distribution of data values on an axis, e.g. a log scaling.
They are defined as subclasses of `ScaleBase`.

See also `.axes.Axes.set_xscale` and the scales examples in the documentation.

See :doc:`/gallery/scales/custom_scale` for a full example of defining a custom
scale.

Matplotlib also supports non-separable transformations that operate on both
`~.axis.Axis` at the same time.  They are known as projections, and defined in
`matplotlib.projections`.
    N)ma)_api	docstring)
NullFormatterScalarFormatterLogFormatterSciNotationLogitFormatterNullLocator
LogLocatorAutoLocatorAutoMinorLocatorSymmetricalLogLocatorLogitLocator)	TransformIdentityTransformc               @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )	ScaleBasea  
    The base class for all scales.

    Scales are separable transformations, working on a single dimension.

    Subclasses should override

    :attr:`name`
        The scale's name.
    :meth:`get_transform`
        A method returning a `.Transform`, which converts data coordinates to
        scaled coordinates.  This transform should be invertible, so that e.g.
        mouse positions can be converted back to data coordinates.
    :meth:`set_default_locators_and_formatters`
        A method that sets default locators and formatters for an `~.axis.Axis`
        that uses this scale.
    :meth:`limit_range_for_scale`
        An optional method that "fixes" the axis range to acceptable values,
        e.g. restricting log-scaled axes to positive values.
    c             C   s   dS )a  
        Construct a new scale.

        Notes
        -----
        The following note is for scale implementors.

        For back-compatibility reasons, scales take an `~matplotlib.axis.Axis`
        object as first argument.  However, this argument should not
        be used: a single scale object should be usable by multiple
        `~matplotlib.axis.Axis`\es at the same time.
        N )selfaxisr   r   ]/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/matplotlib/scale.py__init__4   s    zScaleBase.__init__c             C   s
   t  dS )zL
        Return the `.Transform` object associated with this scale.
        N)NotImplementedError)r   r   r   r   get_transformB   s    zScaleBase.get_transformc             C   s
   t  dS )zi
        Set the locators and formatters of *axis* to instances suitable for
        this scale.
        N)r   )r   r   r   r   r   #set_default_locators_and_formattersH   s    z-ScaleBase.set_default_locators_and_formattersc             C   s   ||fS )z
        Return the range *vmin*, *vmax*, restricted to the
        domain supported by this scale (if any).

        *minpos* should be the minimum positive value in the data.
        This is used by log scales to determine a minimum value.
        r   )r   vminvmaxminposr   r   r   limit_range_for_scaleO   s    zScaleBase.limit_range_for_scaleN)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r      s
   r   c               @   s,   e Zd ZdZdZdd Zdd Zdd Zd	S )
LinearScalez#
    The default linear scale.
    linearc             C   s   dS )z	
        Nr   )r   r   r   r   r   r   a   s    zLinearScale.__init__c             C   sj   | t  |t  |t  |jdkr8tjd sL|jdkrZtjd rZ|	t
  n|	t  d S )Nxzxtick.minor.visibleyzytick.minor.visible)set_major_locatorr   set_major_formatterr   set_minor_formatterr   	axis_namemplrcParamsset_minor_locatorr   r	   )r   r   r   r   r   r   h   s    z/LinearScale.set_default_locators_and_formattersc             C   s   t  S )z
        Return the transform for linear scaling, which is just the
        `~matplotlib.transforms.IdentityTransform`.
        )r   )r   r   r   r   r   t   s    zLinearScale.get_transformN)r   r   r    r!   namer   r   r   r   r   r   r   r"   Z   s
   r"   c                   s8   e Zd ZdZd ZZ fddZdd Zdd Z  Z	S )	FuncTransformzi
    A simple transform that takes and arbitrary function for the
    forward and inverse transform.
       c                s4   t    t|r(t|r(|| _|| _ntddS )a  
        Parameters
        ----------
        forward : callable
            The forward function for the transform.  This function must have
            an inverse and, for best behavior, be monotonic.
            It must have the signature::

               def forward(values: array-like) -> array-like

        inverse : callable
            The inverse of the forward function.  Signature as ``forward``.
        z,arguments to FuncTransform must be functionsN)superr   callable_forward_inverse
ValueError)r   forwardinverse)	__class__r   r   r      s
    
zFuncTransform.__init__c             C   s
   |  |S )N)r2   )r   valuesr   r   r   transform_non_affine   s    z"FuncTransform.transform_non_affinec             C   s   t | j| jS )N)r.   r3   r2   )r   r   r   r   inverted   s    zFuncTransform.inverted)
r   r   r    r!   
input_dimsoutput_dimsr   r9   r:   __classcell__r   r   )r7   r   r.   |   s
   r.   c               @   s,   e Zd ZdZdZdd Zdd Zdd Zd	S )
	FuncScalezN
    Provide an arbitrary scale with user-supplied function for the axis.
    functionc             C   s   |\}}t ||}|| _dS )a  
        Parameters
        ----------
        axis : `~matplotlib.axis.Axis`
            The axis for the scale.
        functions : (callable, callable)
            two-tuple of the forward and inverse functions for the scale.
            The forward function must be monotonic.

            Both functions must have the signature::

               def forward(values: array-like) -> array-like
        N)r.   
_transform)r   r   	functionsr5   r6   	transformr   r   r   r      s    
zFuncScale.__init__c             C   s   | j S )z7Return the `.FuncTransform` associated with this scale.)r@   )r   r   r   r   r      s    zFuncScale.get_transformc             C   sj   | t  |t  |t  |jdkr8tjd sL|jdkrZtjd rZ|	t
  n|	t  d S )Nr$   zxtick.minor.visibler%   zytick.minor.visible)r&   r   r'   r   r(   r   r)   r*   r+   r,   r   r	   )r   r   r   r   r   r      s    z-FuncScale.set_default_locators_and_formattersN)r   r   r    r!   r-   r   r   r   r   r   r   r   r>      s
   r>   c                   s>   e Zd Zd ZZd fdd	Zdd Zdd Zd	d
 Z  Z	S )LogTransformr/   clipc                sB   t    |dks|dkr"td|| _tjddd|d| _d S )Nr   r/   z#The log base cannot be <= 0 or == 1TF)rD   mask)nonpositive)r0   r   r4   baser   check_getitem_clip)r   rG   rF   )r7   r   r   r      s    
zLogTransform.__init__c             C   s    d t| j| j| jrdndS )Nz{}(base={}, nonpositive={!r})rD   rE   )formattyper   rG   rI   )r   r   r   r   __str__   s    zLogTransform.__str__c          	   C   sx   t jddd` t jt jdt jdt ji| j}|r>||}nt |}|t | j }| jrjd||dk< W d Q R X |S )Nignore)divideinvalid   
   ir   )	nperrstateeloglog2log10getrG   rI   )r   arU   outr   r   r   r9      s     


z!LogTransform.transform_non_affinec             C   s
   t | jS )N)InvertedLogTransformrG   )r   r   r   r   r:      s    zLogTransform.inverted)rD   )
r   r   r    r;   r<   r   rL   r9   r:   r=   r   r   )r7   r   rC      s
   rC   c                   s<   e Zd Zd ZZ fddZdd Zdd Zdd	 Z  Z	S )
r[   r/   c                s   t    || _d S )N)r0   r   rG   )r   rG   )r7   r   r   r      s    
zInvertedLogTransform.__init__c             C   s   d t| j| jS )Nz{}(base={}))rJ   rK   r   rG   )r   r   r   r   rL      s    zInvertedLogTransform.__str__c             C   s   t | j|S )N)r   powerrG   )r   rY   r   r   r   r9      s    z)InvertedLogTransform.transform_non_affinec             C   s
   t | jS )N)rC   rG   )r   r   r   r   r:      s    zInvertedLogTransform.inverted)
r   r   r    r;   r<   r   rL   r9   r:   r=   r   r   )r7   r   r[      s
   r[   c               @   sJ   e Zd ZdZdZddddddZed	d
 Zdd Zdd Z	dd Z
dS )LogScalezT
    A standard logarithmic scale.  Care is taken to only plot positive values.
    rU   rQ   NrD   )rG   subsrF   c            C   s   t ||| _|| _dS )a  
        Parameters
        ----------
        axis : `~matplotlib.axis.Axis`
            The axis for the scale.
        base : float, default: 10
            The base of the logarithm.
        nonpositive : {'clip', 'mask'}, default: 'clip'
            Determines the behavior for non-positive values. They can either
            be masked as invalid, or clipped to a very small positive number.
        subs : sequence of int, default: None
            Where to place the subticks between each major tick.  For example,
            in a log10 scale, ``[2, 3, 4, 5, 6, 7, 8, 9]`` will place 8
            logarithmically spaced minor ticks between each major tick.
        N)rC   r@   r^   )r   r   rG   r^   rF   r   r   r   r   
  s    zLogScale.__init__c             C   s   | j jS )N)r@   rG   )r   r   r   r   <lambda>      zLogScale.<lambda>c             C   sR   | t| j |t| j |t| j| j |t| j| jd k	d d S )N)ZlabelOnlyBase)r&   r
   rG   r'   r   r,   r^   r(   )r   r   r   r   r   r     s    z,LogScale.set_default_locators_and_formattersc             C   s   | j S )z6Return the `.LogTransform` associated with this scale.)r@   )r   r   r   r   r   (  s    zLogScale.get_transformc             C   s.   t |sd}|dkr|n||dkr(|n|fS )z$Limit the domain to positive values.gYnr   )rR   isfinite)r   r   r   r   r   r   r   r   ,  s    
zLogScale.limit_range_for_scale)r   r   r    r!   r-   r   propertyrG   r   r   r   r   r   r   r   r]     s   	r]   c               @   s2   e Zd ZdZdZdddZedd Zdd	 Zd
S )FuncScaleLogzu
    Provide an arbitrary scale with user-supplied function for the axis and
    then put on a logarithmic axes.
    functionlogrQ   c             C   s&   |\}}d| _ t||t| | _dS )a  
        Parameters
        ----------
        axis : `matplotlib.axis.Axis`
            The axis for the scale.
        functions : (callable, callable)
            two-tuple of the forward and inverse functions for the scale.
            The forward function must be monotonic.

            Both functions must have the signature::

                def forward(values: array-like) -> array-like

        base : float, default: 10
            Logarithmic base of the scale.
        N)r^   r.   rC   r@   )r   r   rA   rG   r5   r6   r   r   r   r   =  s    zFuncScaleLog.__init__c             C   s
   | j jjS )N)r@   _brG   )r   r   r   r   rG   R  s    zFuncScaleLog.basec             C   s   | j S )z3Return the `.Transform` associated with this scale.)r@   )r   r   r   r   r   V  s    zFuncScaleLog.get_transformN)rQ   )	r   r   r    r!   r-   r   rb   rG   r   r   r   r   r   rc   5  s
   
rc   c                   s4   e Zd Zd ZZ fddZdd Zdd Z  ZS )SymmetricalLogTransformr/   c                sp   t    |dkrtd|dkr*td|dkr:td|| _|| _|| _|d| jd   | _t|| _	d S )Ng      ?z'base' must be larger than 1g        z'linthresh' must be positivez'linscale' must be positive)
r0   r   r4   rG   	linthreshlinscale_linscale_adjrR   rU   	_log_base)r   rG   rh   ri   )r7   r   r   r   ^  s    
z SymmetricalLogTransform.__init__c          	   C   sp   t |}t jddd< t || j | jt || j | j   }|| jk}W d Q R X || | j ||< |S )NrM   )rN   rO   )rR   absrS   signrh   rj   rU   rk   )r   rY   abs_arZ   insider   r   r   r9   l  s    
z,SymmetricalLogTransform.transform_non_affinec             C   s   t | j| j| jS )N)InvertedSymmetricalLogTransformrG   rh   ri   )r   r   r   r   r:   v  s    
z SymmetricalLogTransform.inverted)	r   r   r    r;   r<   r   r9   r:   r=   r   r   )r7   r   rf   [  s   
rf   c                   s4   e Zd Zd ZZ fddZdd Zdd Z  ZS )rp   r/   c                sL   t    t|||}|| _|| _||| _|| _|d| jd   | _d S )Ng      ?rg   )	r0   r   rf   rG   rh   rB   invlinthreshri   rj   )r   rG   rh   ri   symlog)r7   r   r   r   ~  s    
z(InvertedSymmetricalLogTransform.__init__c          	   C   sn   t |}t jddd: t || j t | j|| j | j  }|| jk}W d Q R X || | j ||< |S )NrM   )rN   rO   )	rR   rl   rS   rm   rh   r\   rG   rj   rq   )r   rY   rn   rZ   ro   r   r   r   r9     s    
z4InvertedSymmetricalLogTransform.transform_non_affinec             C   s   t | j| j| jS )N)rf   rG   rh   ri   )r   r   r   r   r:     s    z(InvertedSymmetricalLogTransform.inverted)	r   r   r    r;   r<   r   r9   r:   r=   r   r   )r7   r   rp   {  s   	
rp   c               @   s\   e Zd ZdZdZddddddd	Zed
d Zedd Zedd Z	dd Z
dd ZdS )SymmetricalLogScalea  
    The symmetrical logarithmic scale is logarithmic in both the
    positive and negative directions from the origin.

    Since the values close to zero tend toward infinity, there is a
    need to have a range around zero that is linear.  The parameter
    *linthresh* allows the user to specify the size of this range
    (-*linthresh*, *linthresh*).

    Parameters
    ----------
    base : float, default: 10
        The base of the logarithm.

    linthresh : float, default: 2
        Defines the range ``(-x, x)``, within which the plot is linear.
        This avoids having the plot go to infinity around zero.

    subs : sequence of int
        Where to place the subticks between each major tick.
        For example, in a log10 scale: ``[2, 3, 4, 5, 6, 7, 8, 9]`` will place
        8 logarithmically spaced minor ticks between each major tick.

    linscale : float, optional
        This allows the linear range ``(-linthresh, linthresh)`` to be
        stretched relative to the logarithmic range. Its value is the number of
        decades to use for each half of the linear range. For example, when
        *linscale* == 1.0 (the default), the space used for the positive and
        negative halves of the linear range will be equal to one decade in
        the logarithmic range.
    rr   rQ   rP   Nr/   )rG   rh   r^   ri   c            C   s   t |||| _|| _d S )N)rf   r@   r^   )r   r   rG   rh   r^   ri   r   r   r   r     s    zSymmetricalLogScale.__init__c             C   s   | j jS )N)r@   rG   )r   r   r   r   r_     r`   zSymmetricalLogScale.<lambda>c             C   s   | j jS )N)r@   rh   )r   r   r   r   r_     r`   c             C   s   | j jS )N)r@   ri   )r   r   r   r   r_     r`   c             C   sH   | t|   |t| j |t|  | j |t	  d S )N)
r&   r   r   r'   r   rG   r,   r^   r(   r   )r   r   r   r   r   r     s
    
z7SymmetricalLogScale.set_default_locators_and_formattersc             C   s   | j S )zAReturn the `.SymmetricalLogTransform` associated with this scale.)r@   )r   r   r   r   r     s    z!SymmetricalLogScale.get_transform)r   r   r    r!   r-   r   rb   rG   rh   ri   r   r   r   r   r   r   rs     s   rs   c                   s>   e Zd Zd ZZd fdd	Zdd Zdd Zd	d
 Z  Z	S )LogitTransformr/   rE   c                s6   t    tjddg|d || _ddd| | _d S )NrE   rD   )rF   TF)rD   rE   )r0   r   r   Zcheck_in_list_nonpositiverI   )r   rF   )r7   r   r   r     s    
zLogitTransform.__init__c          	   C   sN   t jddd t |d|  }W dQ R X | jrJd||dk< d|d|k< |S )z,logit transform (base 10), masked or clippedrM   )rN   rO   r/   Nir   i  )rR   rS   rW   rI   )r   rY   rZ   r   r   r   r9     s    z#LogitTransform.transform_non_affinec             C   s
   t | jS )N)LogisticTransformru   )r   r   r   r   r:     s    zLogitTransform.invertedc             C   s   d t| j| jS )Nz{}({!r}))rJ   rK   r   ru   )r   r   r   r   rL     s    zLogitTransform.__str__)rE   )
r   r   r    r;   r<   r   r9   r:   rL   r=   r   r   )r7   r   rt     s
   	rt   c                   s>   e Zd Zd ZZd fdd	Zdd Zdd Zd	d
 Z  Z	S )rv   r/   rE   c                s   t    || _d S )N)r0   r   ru   )r   rF   )r7   r   r   r     s    
zLogisticTransform.__init__c             C   s   ddd|    S )zlogistic transform (base 10)g      ?r/   rQ   r   )r   rY   r   r   r   r9     s    z&LogisticTransform.transform_non_affinec             C   s
   t | jS )N)rt   ru   )r   r   r   r   r:     s    zLogisticTransform.invertedc             C   s   d t| j| jS )Nz{}({!r}))rJ   rK   r   ru   )r   r   r   r   rL     s    zLogisticTransform.__str__)rE   )
r   r   r    r;   r<   r   r9   r:   rL   r=   r   r   )r7   r   rv     s
   rv   c               @   s>   e Zd ZdZdZddddddZd	d
 Zdd Zdd ZdS )
LogitScalez
    Logit scale for data between zero and one, both excluded.

    This scale is similar to a log scale close to zero and to one, and almost
    linear around 0.5. It maps the interval ]0, 1[ onto ]-infty, +infty[.
    logitrE   z\frac{1}{2}F)one_halfuse_overlinec            C   s   t || _|| _|| _dS )a  
        Parameters
        ----------
        axis : `matplotlib.axis.Axis`
            Currently unused.
        nonpositive : {'mask', 'clip'}
            Determines the behavior for values beyond the open interval ]0, 1[.
            They can either be masked as invalid, or clipped to a number very
            close to 0 or 1.
        use_overline : bool, default: False
            Indicate the usage of survival notation (\overline{x}) in place of
            standard notation (1-x) for probability close to one.
        one_half : str, default: r"\frac{1}{2}"
            The string used for ticks formatter to represent 1/2.
        N)rt   r@   _use_overline	_one_half)r   r   rF   ry   rz   r   r   r   r     s    
zLogitScale.__init__c             C   s   | j S )z8Return the `.LogitTransform` associated with this scale.)r@   )r   r   r   r   r     s    zLogitScale.get_transformc             C   sN   | t  |t| j| jd |tdd |td| j| jd d S )N)ry   rz   T)minor)r}   ry   rz   )r&   r   r'   r   r|   r{   r,   r(   )r   r   r   r   r   r     s    z.LogitScale.set_default_locators_and_formattersc             C   s2   t |sd}|dkr|n||dkr,d| n|fS )zH
        Limit the domain to values between 0 and 1 (excluded).
        gHz>r   r/   )rR   ra   )r   r   r   r   r   r   r   r   -  s    
z LogitScale.limit_range_for_scaleN)rE   )	r   r   r    r!   r-   r   r   r   r   r   r   r   r   rw     s   rw   )r#   rU   rr   rx   r?   rd   c               C   s   t tS )z)Return the names of the available scales.)sorted_scale_mappingr   r   r   r   get_scale_namesA  s    r   c             K   s<   | |   kr"tjddd |   } tjt| d}||f|S )z
    Return a scale class by name.

    Parameters
    ----------
    scale : {%(names)s}
    axis : `matplotlib.axis.Axis`
    z3.5zjSupport for case-insensitive scales is deprecated since %(since)s and support will be removed %(removal)s.)message)scale)lowerr   Zwarn_deprecatedrH   r   )r   r   kwargsZ	scale_clsr   r   r   scale_factoryF  s    	
r   namesz, c             C   s   | t | j< dS )z
    Register a new kind of scale.

    Parameters
    ----------
    scale_class : subclass of `ScaleBase`
        The scale to register.
    N)r   r-   )scale_classr   r   r   register_scale]  s    	r   c           	   C   sT   g } xDt  D ]8\}}t|jp$d}| d|dt|ddg qW d| S )zF
    Helper function for generating docstrings related to scales.
     z    z        
)	r   itemsinspectgetdocr   extendtextwrapindentjoin)docsr-   r   r   r   r   r   _get_scale_docsi  s    
r   z{%s}c             C   s   g | ]}t |qS r   )repr).0r$   r   r   r   
<listcomp>z  s    r   )Z
scale_typeZ
scale_docs)1r!   r   r   numpyrR   r   Z
matplotlibr*   r   r   Zmatplotlib.tickerr   r   r   r   r	   r
   r   r   r   r   Zmatplotlib.transformsr   r   r   r"   r.   r>   rC   r[   r]   rc   rf   rp   rs   rt   rv   rw   r   r   r   r   mapr   r   r   Zinterpdupdaterstripr   r   r   r   <module>   sL   0<"$*)1& 7@