3
ƽhG\                 @   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 ddl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*j+e,e-e) i e*_ d+d, Z.d-d. Z/e	j0j1d/d*j+d0d1 e) D  e/ j2 d2 dS )3a  
Scales define the distribution of data values on an axis, e.g. a log scaling.

They are attached to an `~.axis.Axis` and hold a `.Transform`, which is
responsible for the actual data transformation.

See also `.axes.Axes.set_xscale` and the scales examples in the documentation.
    N)ma)cbook	docstring)
NullFormatterScalarFormatterLogFormatterSciNotationLogitFormatterNullLocator
LogLocatorAutoLocatorAutoMinorLocatorSymmetricalLogLocatorLogitLocator)	TransformIdentityTransform)warn_deprecatedc               @   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.

    Any subclasses will want to override:

    - :attr:`name`
    - :meth:`get_transform`
    - :meth:`set_default_locators_and_formatters`

    And optionally:

    - :meth:`limit_range_for_scale`

    c             K   s&   |r"t dddtt|dd 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.
        z3.2z3.4z-ScaleBase got an unexpected keyword argument z(. This will become an error %(removal)s.)removalmessageN)r   nextiter)selfaxiskwargs r   6/tmp/pip-build-7iwl8md4/matplotlib/matplotlib/scale.py__init__,   s    zScaleBase.__init__c             C   s
   t  dS )zq
        Return the :class:`~matplotlib.transforms.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_formattersI   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_scaleP   s    zScaleBase.limit_range_for_scaleN)__name__
__module____qualname____doc__r   r   r   r#   r   r   r   r   r      s
   r   c                   s4   e Zd ZdZdZ fddZdd Zdd Z  ZS )	LinearScalez#
    The default linear scale.
    linearc                s   t  j|f| dS )z	
        N)superr   )r   r   r   )	__class__r   r   r   b   s    zLinearScale.__init__c             C   sj   |j t  |jt  |jt  |jdkr8tjd sL|jdkrZtjd rZ|j	t
  n|j	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   j   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   v   s    zLinearScale.get_transform)	r$   r%   r&   r'   namer   r   r   __classcell__r   r   )r+   r   r(   [   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  j  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)r*   r   callable_forward_inverse
ValueError)r   forwardinverse)r+   r   r   r      s
    
zFuncTransform.__init__c             C   s
   | j |S )N)r:   )r   valuesr   r   r   transform_non_affine   s    z"FuncTransform.transform_non_affinec             C   s   t | j| jS )N)r7   r;   r:   )r   r   r   r   inverted   s    zFuncTransform.inverted)
r$   r%   r&   r'   
input_dimsoutput_dimsr   r@   rA   r6   r   r   )r+   r   r7   ~   s
   r7   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)r7   
_transform)r   r   	functionsr=   r>   	transformr   r   r   r      s    
zFuncScale.__init__c             C   s   | j S )z7Return the `.FuncTransform` associated with this scale.)rF   )r   r   r   r   r      s    zFuncScale.get_transformc             C   sj   |j t  |jt  |jt  |jdkr8tjd sL|jdkrZtjd rZ|j	t
  n|j	t  d S )Nr,   zxtick.minor.visibler-   zytick.minor.visible)r.   r   r/   r   r0   r   r1   r2   r3   r4   r   r	   )r   r   r   r   r   r      s    z-FuncScale.set_default_locators_and_formattersN)r$   r%   r&   r'   r5   r   r   r   r   r   r   r   rD      s
   rD   c               @   sD   e Zd Zd ZZejddddddZdd	 Zd
d Z	dd Z
dS )LogTransformr8   z3.3nonposnonpositiveclipc             C   sB   t j|  |dks|dkr"td|| _tjddd|d| _d S )Nr   r8   z#The log base cannot be <= 0 or == 1TF)rL   mask)rK   )r   r   r<   baser   Z_check_getitem_clip)r   rN   rK   r   r   r   r      s    
zLogTransform.__init__c             C   s    dj t| j| j| jrdndS )Nz{}(base={}, nonpositive={!r})rL   rM   )formattyper$   rN   rO   )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| j}|r>||}nt j|}|t j| j }| jrjd||dk< W d Q R X |S )Nignore)divideinvalid   
   i  r   i)	nperrstateeloglog2log10getrN   rO   )r   ar[   outr   r   r   r@      s     


z!LogTransform.transform_non_affinec             C   s
   t | jS )N)InvertedLogTransformrN   )r   r   r   r   rA      s    zLogTransform.invertedN)rL   )r$   r%   r&   rB   rC   r   _rename_parameterr   rR   r@   rA   r   r   r   r   rI      s   rI   c               @   s4   e Zd Zd ZZdd Zdd Zdd Zdd	 Zd
S )ra   r8   c             C   s   t j|  || _d S )N)r   r   rN   )r   rN   r   r   r   r      s    
zInvertedLogTransform.__init__c             C   s   dj t| j| jS )Nz{}(base={}))rP   rQ   r$   rN   )r   r   r   r   rR      s    zInvertedLogTransform.__str__c             C   s   t j| j|S )N)r   powerrN   )r   r_   r   r   r   r@      s    z)InvertedLogTransform.transform_non_affinec             C   s
   t | jS )N)rI   rN   )r   r   r   r   rA     s    zInvertedLogTransform.invertedN)	r$   r%   r&   rB   rC   r   rR   r@   rA   r   r   r   r   ra      s
   ra   c               @   st   e Zd ZdZdZejdddedd Zejddded	d
 Z	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.
    r[   z3.3zscale.LogTransform)alternativec             C   s   t S )N)rI   )r   r   r   r   rI     s    zLogScale.LogTransformzscale.InvertedLogTransformc             C   s   t S )N)ra   )r   r   r   r   ra     s    zLogScale.InvertedLogTransformc             K   s   t |dd}tjdd| dtjdd| dtjdd| ddd	d
ddd}|f |\}}}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.
        r1   r,   z3.3rN   subsrJ   rK   rW   NrL   )rN   rf   rK   c             S   s
   | ||fS )Nr   )rN   rf   rK   r   r   r   r   ,  s    z#LogScale.__init__.<locals>.__init__)getattrr   rb   rI   rF   rf   )r   r   r   r1   r   rN   rf   rK   r   r   r   r     s    zLogScale.__init__c             C   s   | j jS )N)rF   rN   )r   r   r   r   <lambda>6  s    zLogScale.<lambda>c             C   sR   |j t| j |jt| j |jt| j| j |jt| j| jd k	d d S )N)ZlabelOnlyBase)r.   r
   rN   r/   r   r4   rf   r0   )r   r   r   r   r   r   8  s    z,LogScale.set_default_locators_and_formattersc             C   s   | j S )z6Return the `.LogTransform` associated with this scale.)rF   )r   r   r   r   r   A  s    zLogScale.get_transformc             C   s.   t j|sd}|dkr|n||dkr(|n|fS )z$Limit the domain to positive values.gYnr   )rX   isfinite)r   r    r!   r"   r   r   r   r#   E  s    
zLogScale.limit_range_for_scaleN)r$   r%   r&   r'   r5   r   
deprecatedpropertyrI   ra   r   rN   r   r   r#   r   r   r   r   rd     s   	rd   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.
    functionlogrW   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)rf   r7   rI   rF   )r   r   rG   rN   r=   r>   r   r   r   r   V  s    zFuncScaleLog.__init__c             C   s
   | j jjS )N)rF   _brN   )r   r   r   r   rN   k  s    zFuncScaleLog.basec             C   s   | j S )z3Return the `.Transform` associated with this scale.)rF   )r   r   r   r   r   o  s    zFuncScaleLog.get_transformN)rW   )	r$   r%   r&   r'   r5   r   rk   rN   r   r   r   r   r   rl   N  s
   
rl   c               @   s,   e Zd Zd ZZdd Zdd Zdd ZdS )	SymmetricalLogTransformr8   c             C   sp   t j|  |dkrtd|dkr*td|dkr:td|| _|| _|| _|d| jd   | _tj|| _	d S )Ng      ?z'base' must be larger than 1g        z'linthresh' must be positivez'linscale' must be positiver8   )
r   r   r<   rN   	linthreshlinscale_linscale_adjrX   r[   	_log_base)r   rN   rq   rr   r   r   r   r   w  s    
z SymmetricalLogTransform.__init__c             C   sp   t j|}t jddd< t j|| j | jt j|| j | j   }|| jk}W d Q R X || | j ||< |S )NrS   )rT   rU   )rX   absrY   signrq   rs   r[   rt   )r   r_   abs_ar`   insider   r   r   r@     s    
z,SymmetricalLogTransform.transform_non_affinec             C   s   t | j| j| jS )N)InvertedSymmetricalLogTransformrN   rq   rr   )r   r   r   r   rA     s    
z SymmetricalLogTransform.invertedN)r$   r%   r&   rB   rC   r   r@   rA   r   r   r   r   ro   t  s   
ro   c               @   s,   e Zd Zd ZZdd Zdd Zdd ZdS )	ry   r8   c             C   sL   t j|  t|||}|| _|| _|j|| _|| _|d| jd   | _d S )Ng      ?r8   rp   )	r   r   ro   rN   rq   rH   invlinthreshrr   rs   )r   rN   rq   rr   symlogr   r   r   r     s    
z(InvertedSymmetricalLogTransform.__init__c             C   sn   t j|}t jddd: t j|| j t j| j|| j | j  }|| jk}W d Q R X || | j ||< |S )NrS   )rT   rU   )	rX   ru   rY   rv   rq   rc   rN   rs   rz   )r   r_   rw   r`   rx   r   r   r   r@     s    
z4InvertedSymmetricalLogTransform.transform_non_affinec             C   s   t | j| j| jS )N)ro   rN   rq   rr   )r   r   r   r   rA     s    z(InvertedSymmetricalLogTransform.invertedN)r$   r%   r&   rB   rC   r   r@   rA   r   r   r   r   ry     s   	
ry   c               @   s   e Zd ZdZdZejdddedd Zejddded	d
 Z	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.
    r{   z3.3zscale.SymmetricalLogTransform)re   c             C   s   t S )N)ro   )r   r   r   r   ro     s    z+SymmetricalLogScale.SymmetricalLogTransformz%scale.InvertedSymmetricalLogTransformc             C   s   t S )N)ry   )r   r   r   r   ry     s    z3SymmetricalLogScale.InvertedSymmetricalLogTransformc       	   	   K   s   t |dd}tjdd| dtjdd| dtjdd| dtjdd| ddd	d d
ddd}|f |\}}}}t|||| _|| _d S )Nr1   r,   z3.3rN   rq   rf   rr   rW   rV   r8   )rN   rq   rf   rr   c             [   s.   |r"t dddtt|dd | |||fS )Nz3.2z3.4z7SymmetricalLogScale got an unexpected keyword argument z(. This will become an error %(removal)s.)r   r   )r   r   r   )rN   rq   rf   rr   r   r   r   r   r     s
    z.SymmetricalLogScale.__init__.<locals>.__init__)rg   r   rb   ro   rF   rf   )	r   r   r   r1   r   rN   rq   rf   rr   r   r   r   r     s    zSymmetricalLogScale.__init__c             C   s   | j jS )N)rF   rN   )r   r   r   r   rh     s    zSymmetricalLogScale.<lambda>c             C   s   | j jS )N)rF   rq   )r   r   r   r   rh     s    c             C   s   | j jS )N)rF   rr   )r   r   r   r   rh     s    c             C   sH   |j t| j  |jt| j |jt| j | j |jt	  d S )N)
r.   r   r   r/   r   rN   r4   rf   r0   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.)rF   )r   r   r   r   r     s    z!SymmetricalLogScale.get_transformN)r$   r%   r&   r'   r5   r   rj   rk   ro   ry   r   rN   rq   rr   r   r   r   r   r   r   r|     s   r|   c               @   sD   e Zd Zd ZZejddddddZdd	 Zd
d Z	dd Z
dS )LogitTransformr8   z3.3rJ   rK   rM   c             C   s6   t j|  tjddg|d || _ddd| | _d S )NrM   rL   )rK   TF)rL   rM   )r   r   r   _check_in_list_nonpositiverO   )r   rK   r   r   r   r     s    
zLogitTransform.__init__c             C   sN   t jddd t j|d|  }W dQ R X | jrJd||dk< d|d|k< |S )z,logit transform (base 10), masked or clippedrS   )rT   rU   r8   Ni  r   i)rX   rY   r]   rO   )r   r_   r`   r   r   r   r@     s    z#LogitTransform.transform_non_affinec             C   s
   t | jS )N)LogisticTransformr   )r   r   r   r   rA     s    zLogitTransform.invertedc             C   s   dj t| j| jS )Nz{}({!r}))rP   rQ   r$   r   )r   r   r   r   rR     s    zLogitTransform.__str__N)rM   )r$   r%   r&   rB   rC   r   rb   r   r@   rA   rR   r   r   r   r   r}     s   	r}   c               @   sD   e Zd Zd ZZejddddddZdd	 Zd
d Z	dd Z
dS )r   r8   z3.3rJ   rK   rM   c             C   s   t j|  || _d S )N)r   r   r   )r   rK   r   r   r   r      s    
zLogisticTransform.__init__c             C   s   ddd|    S )zlogistic transform (base 10)g      ?r8   rW   r   )r   r_   r   r   r   r@   %  s    z&LogisticTransform.transform_non_affinec             C   s
   t | jS )N)r}   r   )r   r   r   r   rA   )  s    zLogisticTransform.invertedc             C   s   dj t| j| jS )Nz{}({!r}))rP   rQ   r$   r   )r   r   r   r   rR   ,  s    zLogisticTransform.__str__N)rM   )r$   r%   r&   rB   rC   r   rb   r   r@   rA   rR   r   r   r   r   r     s   r   c               @   sL   e Zd ZdZdZejddd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[.
    logitz3.3rJ   rK   rM   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)r}   rF   _use_overline	_one_half)r   r   rK   r   r   r   r   r   r   9  s    
zLogitScale.__init__c             C   s   | j S )z8Return the `.LogitTransform` associated with this scale.)rF   )r   r   r   r   r   O  s    zLogitScale.get_transformc             C   sN   |j t  |jt| j| jd |jtdd |jtd| j| jd d S )N)r   r   T)minor)r   r   r   )r.   r   r/   r   r   r   r4   r0   )r   r   r   r   r   r   S  s    z.LogitScale.set_default_locators_and_formattersc             C   s2   t j|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   r8   )rX   ri   )r   r    r!   r"   r   r   r   r#   f  s    
z LogitScale.limit_range_for_scaleN)rM   )r$   r%   r&   r'   r5   r   rb   r   r   r   r#   r   r   r   r   r   0  s   r   )r)   r[   r{   r   rE   rm   c               C   s   t tS )z)Return the names of the available scales.)sorted_scale_mappingr   r   r   r   get_scale_namesz  s    r   c             K   s&   | j  } tjt| d t|  |f|S )z
    Return a scale class by name.

    Parameters
    ----------
    scale : {%(names)s}
    axis : `matplotlib.axis.Axis`
    )scale)lowerr   r~   r   )r   r   r   r   r   r   scale_factory  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   r5   )scale_classr   r   r   register_scale  s    	r   c              C   sL   g } x<t j D ]0\}}| jd|dtjtj|jddg qW dj| S )zF
    Helper function for generating docstrings related to scales.
    z         
z        )	r   itemsextendtextwrapindentinspectgetdocr   join)Zdocsr5   r   r   r   r   _get_scale_docs  s    r   z{%s}c             C   s   g | ]}t |qS r   )repr).0r,   r   r   r   
<listcomp>  s    r   )Z
scale_typeZ
scale_docs)3r'   r   r   numpyrX   r   Z
matplotlibr2   r   r   Zmatplotlib.tickerr   r   r   r   r	   r
   r   r   r   r   Zmatplotlib.transformsr   r   Zmatplotlib.cbookr   r   r(   r7   rD   rI   ra   rd   rl   ro   ry   r|   r}   r   r   r   r   r   r   mapr   r   r   Zinterpdupdaterstripr   r   r   r   <module>   sN   0A#$**G& TA