B
    ]t\=K                 @   s  d dl Zd dl mZ d dlmZ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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"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(d,Z)d-d. Z*d/d0 Z+e,e+j-d1d2.e* i e+_-d3d4 Z/d5d6 Z0ej1j2d2.d7d8 e* D e0 3 d9 dS ):    N)ma)cbook	docstringrcParams)
NullFormatterScalarFormatterLogFormatterSciNotationLogitFormatterNullLocator
LogLocatorAutoLocatorAutoMinorLocatorSymmetricalLogLocatorLogitLocator)	TransformIdentityTransformc               @   s(   e Zd Z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             C   s
   t  dS )zq
        Return the :class:`~matplotlib.transforms.Transform` object
        associated with this scale.
        N)NotImplementedError)self r   /lib/python3.7/site-packages/matplotlib/scale.pyget_transform   s    zScaleBase.get_transformc             C   s
   t  dS )z
        Set the :class:`~matplotlib.ticker.Locator` and
        :class:`~matplotlib.ticker.Formatter` objects on the given
        axis to match this scale.
        N)r   )r   axisr   r   r   #set_default_locators_and_formatters"   s    z-ScaleBase.set_default_locators_and_formattersc             C   s   ||fS )z
        Returns the range *vmin*, *vmax*, possibly limited to the
        domain supported by this scale.

        *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_scale*   s    zScaleBase.limit_range_for_scaleN)__name__
__module____qualname____doc__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             K   s   d S )Nr   )r   r   kwargsr   r   r   __init__<   s    zLinearScale.__init__c             C   sf   | t  |t  |t  |jdkr6td sH|jdkrVtd rV|t	  n|t
  dS )zd
        Set the locators and formatters to reasonable defaults for
        linear scaling.
        xzxtick.minor.visibleyzytick.minor.visibleN)set_major_locatorr   set_major_formatterr   set_minor_formatterr   	axis_namer   set_minor_locatorr   r
   )r   r   r   r   r   r   ?   s    z/LinearScale.set_default_locators_and_formattersc             C   s   t  S )zy
        The transform for linear scaling is just the
        :class:`~matplotlib.transforms.IdentityTransform`.
        )r   )r   r   r   r   r   N   s    zLinearScale.get_transformN)r   r   r    r!   namer%   r   r   r   r   r   r   r"   5   s
   r"   c               @   s6   e Zd ZdZdZdZdZdddZdd Zdd	 Z	d
S )LogTransformBase   Tclipc             C   s   t |  ddd| | _d S )NTF)r0   mask)r   r%   _clip)r   nonposr   r   r   r%   \   s    
zLogTransformBase.__init__c          	   C   sJ   t jddd2 t |}|t | j }| jr<d||dk< W d Q R X |S )Nignore)divideinvalidir   )nperrstatelogbaser2   )r   aoutr   r   r   transform_non_affine`   s    

z%LogTransformBase.transform_non_affinec             C   s   d t| j| jrdndS )Nz{}({!r})r0   r1   )formattyper   r2   )r   r   r   r   __str__r   s    zLogTransformBase.__str__N)r0   )
r   r   r    
input_dimsoutput_dimsis_separablehas_inverser%   r=   r@   r   r   r   r   r.   V   s   
r.   c               @   s,   e Zd ZdZdZdZdZdd Zdd ZdS )InvertedLogTransformBaser/   Tc             C   s   t | j|S )N)r   powerr:   )r   r;   r   r   r   r=   }   s    z-InvertedLogTransformBase.transform_non_affinec             C   s   d t| jS )Nz{}())r>   r?   r   )r   r   r   r   r@      s    z InvertedLogTransformBase.__str__N)	r   r   r    rA   rB   rC   rD   r=   r@   r   r   r   r   rE   w   s   rE   c               @   s   e Zd ZdZdd ZdS )Log10Transformg      $@c             C   s   t  S )N)InvertedLog10Transform)r   r   r   r   inverted   s    zLog10Transform.invertedN)r   r   r    r:   rI   r   r   r   r   rG      s   rG   c               @   s   e Zd ZdZdd ZdS )rH   g      $@c             C   s   t  S )N)rG   )r   r   r   r   rI      s    zInvertedLog10Transform.invertedN)r   r   r    r:   rI   r   r   r   r   rH      s   rH   c               @   s   e Zd ZdZdd ZdS )Log2Transformg       @c             C   s   t  S )N)InvertedLog2Transform)r   r   r   r   rI      s    zLog2Transform.invertedN)r   r   r    r:   rI   r   r   r   r   rJ      s   rJ   c               @   s   e Zd ZdZdd ZdS )rK   g       @c             C   s   t  S )N)rJ   )r   r   r   r   rI      s    zInvertedLog2Transform.invertedN)r   r   r    r:   rI   r   r   r   r   rK      s   rK   c               @   s   e Zd ZejZdd ZdS )NaturalLogTransformc             C   s   t  S )N)InvertedNaturalLogTransform)r   r   r   r   rI      s    zNaturalLogTransform.invertedN)r   r   r    r7   er:   rI   r   r   r   r   rL      s   rL   c               @   s   e Zd ZejZdd ZdS )rM   c             C   s   t  S )N)rL   )r   r   r   r   rI      s    z$InvertedNaturalLogTransform.invertedN)r   r   r    r7   rN   r:   rI   r   r   r   r   rM      s   rM   c               @   s   e Zd ZdddZdd ZdS )LogTransformr0   c             C   s   t | | || _d S )N)r.   r%   r:   )r   r:   r3   r   r   r   r%      s    zLogTransform.__init__c             C   s
   t | jS )N)InvertedLogTransformr:   )r   r   r   r   rI      s    zLogTransform.invertedN)r0   )r   r   r    r%   rI   r   r   r   r   rO      s   
rO   c               @   s   e Zd Zdd Zdd ZdS )rP   c             C   s   t |  || _d S )N)rE   r%   r:   )r   r:   r   r   r   r%      s    
zInvertedLogTransform.__init__c             C   s
   t | jS )N)rO   r:   )r   r   r   r   rI      s    zInvertedLogTransform.invertedN)r   r   r    r%   rI   r   r   r   r   rP      s   rP   c               @   sX   e Zd ZdZdZeZeZeZeZe	Z	e
Z
eZeZeZdd Zdd Zdd Zd	d
 ZdS )LogScalea  
    A standard logarithmic scale.  Care is taken so non-positive
    values are not plotted.

    For computational efficiency (to push as much as possible to Numpy
    C code in the common cases), this scale provides different
    transforms depending on the base of the logarithm:

       - base 10 (:class:`Log10Transform`)
       - base 2 (:class:`Log2Transform`)
       - base e (:class:`NaturalLogTransform`)
       - arbitrary base (:class:`LogTransform`)
    r9   c             K   s   |j dkr0|dd}|dd}|dd}n$|dd}|d	d}|d
d}t|rntdd| |dkr~td|dks|dkrtd|dkr| || _n<|dkr| || _n&|tj	kr| 
|| _n| ||| _|| _|| _dS )a   
        *basex*/*basey*:
           The base of the logarithm

        *nonposx*/*nonposy*: {'mask', 'clip'}
          non-positive values in *x* or *y* can be masked as
          invalid, or clipped to a very small positive number

        *subsx*/*subsy*:
           Where to place the subticks between each major tick.
           Should be a sequence of integers.  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.
        r&   basexg      $@subsxNZnonposxr0   baseysubsyZnonposyzrprovided too many kwargs, can only pass {'basex', 'subsx', nonposx'} or {'basey', 'subsy', nonposy'}.  You passed z{!r})r1   r0   z/nonposx, nonposy kwarg must be 'mask' or 'clip'r   r/   z#The log base cannot be <= 0 or == 1g       @)r+   poplen
ValueErrorr>   rG   
_transformrJ   r7   rN   rL   rO   r:   subs)r   r   r$   r:   rZ   r3   r   r   r   r%      s.    

zLogScale.__init__c             C   sR   | t| j |t| j |t| j| j |t| j| jdk	d dS )zb
        Set the locators and formatters to specialized versions for
        log scaling.
        N)ZlabelOnlyBase)r(   r   r:   r)   r   r,   rZ   r*   )r   r   r   r   r   r     s    z,LogScale.set_default_locators_and_formattersc             C   s   | j S )z
        Return a :class:`~matplotlib.transforms.Transform` instance
        appropriate for the given logarithm base.
        )rY   )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 )z6
        Limit the domain to positive values.
        gYnr   )r7   isfinite)r   r   r   r   r   r   r   r     s    
zLogScale.limit_range_for_scaleN)r   r   r    r!   r-   r.   rG   rH   rJ   rK   rL   rM   rO   rP   r%   r   r   r   r   r   r   r   rQ      s   1rQ   c               @   s4   e Zd ZdZdZdZdZdd Zdd Zdd Z	d	S )
SymmetricalLogTransformr/   Tc             C   s@   t |  || _|| _|| _|d| jd   | _t|| _d S )Ng      ?)	r   r%   r:   	linthreshlinscale_linscale_adjr7   r9   	_log_base)r   r:   r^   r_   r   r   r   r%   1  s    
z SymmetricalLogTransform.__init__c             C   sv   t |}tj|| j | jdd}|| j | jtt || j | j   }|j	
 rnt|j	|| j |S |S d S )NF)copy)r7   signr   masked_insider^   r`   r9   absra   r1   anywhere)r   r;   rc   maskedr9   r   r   r   r=   9  s    
 
z,SymmetricalLogTransform.transform_non_affinec             C   s   t | j| j| jS )N)InvertedSymmetricalLogTransformr:   r^   r_   )r   r   r   r   rI   G  s    
z SymmetricalLogTransform.invertedN)
r   r   r    rA   rB   rC   rD   r%   r=   rI   r   r   r   r   r\   +  s   r\   c               @   s4   e Zd ZdZdZdZdZdd Zdd Zdd Z	d	S )
ri   r/   Tc             C   sL   t |  t|||}|| _|| _||| _|| _|d| jd   | _d S )Ng      ?r]   )	r   r%   r\   r:   r^   Z	transforminvlinthreshr_   r`   )r   r:   r^   r_   symlogr   r   r   r%   R  s    
z(InvertedSymmetricalLogTransform.__init__c             C   sr   t |}tj|| j | jdd}|| j t| j||| j  | j  }|j	
 rjt|j	|| j |S |S d S )NF)rb   )r7   rc   r   rd   rj   r^   rF   r:   r`   r1   rf   rg   )r   r;   rc   rh   Zexpr   r   r   r=   [  s    

z4InvertedSymmetricalLogTransform.transform_non_affinec             C   s   t | j| j| jS )N)r\   r:   r^   r_   )r   r   r   r   rI   g  s    z(InvertedSymmetricalLogTransform.invertedN)
r   r   r    rA   rB   rC   rD   r%   r=   rI   r   r   r   r   ri   L  s   	ri   c               @   s4   e Zd ZdZdZeZeZdd Zdd Zdd Z	d	S )
SymmetricalLogScaleah  
    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*).
    rk   c             K   s   |j dkr<|dd}|dd}|dd}|dd	}n0|d
d}|dd}|dd}|dd	}|d	kr|td|dkrtd|dkrtd| |||| _|| _|| _|| _|| _dS )a"  
        *basex*/*basey*:
           The base of the logarithm

        *linthreshx*/*linthreshy*:
          A single float which defines the range (-*x*, *x*), within
          which the plot is linear. This avoids having the plot go to
          infinity around zero.

        *subsx*/*subsy*:
           Where to place the subticks between each major tick.
           Should be a sequence of integers.  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.

        *linscalex*/*linscaley*:
           This allows the linear range (-*linthresh* to *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&   rR   g      $@Z
linthreshxg       @rS   NZ	linscalexg      ?rT   Z
linthreshyrU   Z	linscaleyz#'basex/basey' must be larger than 1g        z('linthreshx/linthreshy' must be positivez''linscalex/linthreshy' must be positive)	r+   rV   rX   r\   rY   r:   r^   r_   rZ   )r   r   r$   r:   r^   rZ   r_   r   r   r   r%   {  s,    
zSymmetricalLogScale.__init__c             C   sH   | t|   |t| j |t|  | j |t	  dS )zn
        Set the locators and formatters to specialized versions for
        symmetrical log scaling.
        N)
r(   r   r   r)   r   r:   r,   rZ   r*   r   )r   r   r   r   r   r     s
    
z7SymmetricalLogScale.set_default_locators_and_formattersc             C   s   | j S )zE
        Return a :class:`SymmetricalLogTransform` instance.
        )rY   )r   r   r   r   r     s    z!SymmetricalLogScale.get_transformN)
r   r   r    r!   r-   r\   ri   r%   r   r   r   r   r   r   rl   l  s   	6rl   c               @   s>   e Zd ZdZdZdZdZdddZdd Zdd	 Z	d
d Z
dS )LogitTransformr/   Tr1   c             C   s$   t |  || _ddd| | _d S )NTF)r0   r1   )r   r%   _nonposr2   )r   r3   r   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 clippedr4   )r5   r6   r/   Nir   i  )r7   r8   Zlog10r2   )r   r;   r<   r   r   r   r=     s    z#LogitTransform.transform_non_affinec             C   s
   t | jS )N)LogisticTransformrn   )r   r   r   r   rI     s    zLogitTransform.invertedc             C   s   d t| j| jrdndS )Nz{}({!r})r0   r1   )r>   r?   r   r2   )r   r   r   r   r@     s    zLogitTransform.__str__N)r1   )r   r   r    rA   rB   rC   rD   r%   r=   rI   r@   r   r   r   r   rm     s   
	rm   c               @   s>   e Zd ZdZdZdZdZdddZdd Zdd	 Z	d
d Z
dS )ro   r/   Tr1   c             C   s   t |  || _d S )N)r   r%   rn   )r   r3   r   r   r   r%     s    
zLogisticTransform.__init__c             C   s   ddd|    S )zlogistic transform (base 10)g      ?r/   
   r   )r   r;   r   r   r   r=     s    z&LogisticTransform.transform_non_affinec             C   s
   t | jS )N)rm   rn   )r   r   r   r   rI     s    zLogisticTransform.invertedc             C   s   d t| j| jS )Nz{}({!r}))r>   r?   r   rn   )r   r   r   r   r@     s    zLogisticTransform.__str__N)r1   )r   r   r    rA   rB   rC   rD   r%   r=   rI   r@   r   r   r   r   ro     s   
ro   c               @   s6   e Zd ZdZdZ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[.
    logitr1   c             C   s   |dkrt dt|| _dS )z
        *nonpos*: {'mask', 'clip'}
          values beyond ]0, 1[ can be masked as invalid, or clipped to a number
          very close to 0 or 1
        )r1   r0   z/nonposx, nonposy kwarg must be 'mask' or 'clip'N)rX   rm   rY   )r   r   r3   r   r   r   r%     s    zLogitScale.__init__c             C   s   | j S )z<
        Return a :class:`LogitTransform` instance.
        )rY   )r   r   r   r   r     s    zLogitScale.get_transformc             C   s8   | t  |t  |tdd |t  d S )NT)minor)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/   )r7   r[   )r   r   r   r   r   r   r   r     s    
z LogitScale.limit_range_for_scaleN)r1   )	r   r   r    r!   r-   r%   r   r   r   r   r   r   r   rq     s   
rq   )r#   r9   rk   rr   c               C   s   t tS )N)sorted_scale_mappingr   r   r   r   get_scale_names(  s    rv   c             K   s8   |   } | dkrd} | tkr(td|  t|  |f|S )zC
    Return a scale class by name.

    ACCEPTS: [ %(names)s ]
    Nr#   zUnknown scale type '%s')lowerru   rX   )scaler   r$   r   r   r   scale_factory,  s    ry   namesz | c             C   s   | t | j< dS )zd
    Register a new kind of scale.

    *scale_class* must be a subclass of :class:`ScaleBase`.
    N)ru   r-   )scale_classr   r   r   register_scale>  s    r|   c              C   sz   g } xjt  D ]`}t| }| d|  | d t|jj}ddd |dD }| | | d qW d| S )zF
    Helper function for generating docstrings related to scales.
    z    '%s' c             S   s   g | ]}d | qS )z        %s
r   ).0r&   r   r   r   
<listcomp>Q  s   z"get_scale_docs.<locals>.<listcomp>
)	rv   ru   appendr   dedentr%   r!   joinsplit)Zdocsr-   r{   Z
class_docsr   r   r   get_scale_docsG  s    


r   c             C   s   g | ]}t |qS r   )repr)r~   r&   r   r   r   r   Y  s    r   )rx   Z
scale_docs)4Znumpyr7   r   Z
matplotlibr   r   r   Zmatplotlib.tickerr   r   r   r	   r
   r   r   r   r   r   Zmatplotlib.transformsr   r   objectr   r"   r.   rE   rG   rH   rJ   rK   rL   rM   rO   rP   rQ   r\   ri   rl   rm   ro   rq   ru   rv   ry   r   r!   r   r|   r   Zinterpdupdaterstripr   r   r   r   <module>   sH   0)!!		k! W-
	