a
    ضa0T                     @   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   `/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/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.
        Nr   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   ZvminZvmaxZ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   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   Z	axis_namemplZrcParamsset_minor_locatorr   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)r3   )r   valuesr   r   r   transform_non_affine   s    z"FuncTransform.transform_non_affinec                 C   s   t | j| jS r:   )r/   r4   r3   r   r   r   r   inverted   s    zFuncTransform.inverted)
r   r    r!   r"   
input_dimsoutput_dimsr   r<   r=   __classcell__r   r   r8   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   	functionsr6   r7   	transformr   r   r   r      s    
zFuncScale.__init__c                 C   s   | j S )z7Return the `.FuncTransform` associated with this scale.rC   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 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   rA      s
   rA   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 )LogTransformr0   clipc                    sB   t    |dks|dkr"td|| _tjddd|d| _d S )Nr   r0   z#The log base cannot be <= 0 or == 1TFrH   masknonpositive)r1   r   r5   baser   check_getitem_clip)r   rM   rL   r8   r   r   r      s    

zLogTransform.__init__c                 C   s    d t| j| j| jrdndS )Nz{}(base={}, nonpositive={!r})rH   rJ   )formattyper   rM   rO   r   r   r   r   __str__   s    zLogTransform.__str__c                 C   s   t jdddj t jt jdt jdt ji| j}|r>||}nt |}|t | j }| jrjd||dk< W d    n1 s~0    Y  |S )Nignoredivideinvalid   
   r   )	nperrstateeloglog2log10getrM   rO   )r   ar]   outr   r   r   r<      s     


*z!LogTransform.transform_non_affinec                 C   s
   t | jS r:   )InvertedLogTransformrM   r   r   r   r   r=      s    zLogTransform.inverted)rH   
r   r    r!   r>   r?   r   rR   r<   r=   r@   r   r   r8   r   rG      s
   rG   c                       s<   e Zd Zd ZZ fddZdd Zdd Zdd	 Z  Z	S )
rc   r0   c                    s   t    || _d S r:   )r1   r   rM   )r   rM   r8   r   r   r      s    
zInvertedLogTransform.__init__c                 C   s   d t| j| jS )Nz{}(base={}))rP   rQ   r   rM   r   r   r   r   rR      s    zInvertedLogTransform.__str__c                 C   s   t | j|S r:   )r   powerrM   r   ra   r   r   r   r<      s    z)InvertedLogTransform.transform_non_affinec                 C   s
   t | jS r:   )rG   rM   r   r   r   r   r=      s    zInvertedLogTransform.invertedrd   r   r   r8   r   rc      s
   rc   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.
    r]   rX   NrH   )rM   subsrL   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)rG   rC   rh   )r   r   rM   rh   rL   r   r   r   r   
  s    zLogScale.__init__c                 C   s   | j jS r:   rC   rM   r   r   r   r   <lambda>      zLogScale.<lambda>c                 C   sR   | t| j |t| j |t| j| j |t| j| jd ud d S )N)ZlabelOnlyBase)r)   r
   rM   r*   r   r-   rh   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.rF   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   rZ   isfiniter   r   r   r   r   ,  s
    
zLogScale.limit_range_for_scale)r   r    r!   r"   r.   r   propertyrM   r   r   r   r   r   r   r   rg     s   	rg   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.
    functionlogrX   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)rh   r/   rG   rC   )r   r   rD   rM   r6   r7   r   r   r   r   =  s    zFuncScaleLog.__init__c                 C   s
   | j jjS r:   )rC   _brM   r   r   r   r   rM   R  s    zFuncScaleLog.basec                 C   s   | j S )z3Return the `.Transform` associated with this scale.rF   r   r   r   r   r   V  s    zFuncScaleLog.get_transformN)rX   )	r   r    r!   r"   r.   r   rn   rM   r   r   r   r   r   ro   5  s   

ro   c                       s4   e Zd Zd ZZ fddZdd Zdd Z  ZS )SymmetricalLogTransformr0   c                    sp   t    |dkrtd|dkr*td|dkr:td|| _|| _|| _|d| jd   | _t|| _	d S )N      ?z'base' must be larger than 1g        z'linthresh' must be positivez'linscale' must be positive)
r1   r   r5   rM   	linthreshlinscale_linscale_adjrZ   r]   	_log_base)r   rM   ru   rv   r8   r   r   r   ^  s    
z SymmetricalLogTransform.__init__c                 C   s   t |}t jdddF t || j | jt || j | j   }|| jk}W d    n1 sd0    Y  || | j ||< |S NrS   rT   )rZ   absr[   signru   rw   r]   rx   r   ra   Zabs_arb   Zinsider   r   r   r<   l  s    
(z,SymmetricalLogTransform.transform_non_affinec                 C   s   t | j| j| jS r:   )InvertedSymmetricalLogTransformrM   ru   rv   r   r   r   r   r=   v  s    
z SymmetricalLogTransform.inverted	r   r    r!   r>   r?   r   r<   r=   r@   r   r   r8   r   rr   [  s   
rr   c                       s4   e Zd Zd ZZ fddZdd Zdd Z  ZS )r}   r0   c                    sL   t    t|||}|| _|| _||| _|| _|d| jd   | _d S )Nrs   rt   )	r1   r   rr   rM   ru   rE   invlinthreshrv   rw   )r   rM   ru   rv   symlogr8   r   r   r   ~  s    
z(InvertedSymmetricalLogTransform.__init__c                 C   s   t |}t jdddD t || j t | j|| j | j  }|| jk}W d    n1 sb0    Y  || | j ||< |S ry   )	rZ   rz   r[   r{   ru   re   rM   rw   r   r|   r   r   r   r<     s    
(z4InvertedSymmetricalLogTransform.transform_non_affinec                 C   s   t | j| j| jS r:   )rr   rM   ru   rv   r   r   r   r   r=     s    z(InvertedSymmetricalLogTransform.invertedr~   r   r   r8   r   r}   {  s   	
r}   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.
    r   rX   rW   Nr0   )rM   ru   rh   rv   c                C   s   t |||| _|| _d S r:   )rr   rC   rh   )r   r   rM   ru   rh   rv   r   r   r   r     s    zSymmetricalLogScale.__init__c                 C   s   | j jS r:   ri   r   r   r   r   rj     rk   zSymmetricalLogScale.<lambda>c                 C   s   | j jS r:   )rC   ru   r   r   r   r   rj     rk   c                 C   s   | j jS r:   )rC   rv   r   r   r   r   rj     rk   c                 C   sH   | t|   |t| j |t|  | j |t	  d S r:   )
r)   r   r   r*   r   rM   r-   rh   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_transform)r   r    r!   r"   r.   r   rn   rM   ru   rv   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 )LogitTransformr0   rJ   c                    s6   t    tjddg|d || _ddd| | _d S )NrJ   rH   rK   TFrI   )r1   r   r   Zcheck_in_list_nonpositiverO   r   rL   r8   r   r   r     s    
zLogitTransform.__init__c                 C   sb   t jddd" t |d|  }W d   n1 s60    Y  | jr^d||dk< d|d|k< |S )z,logit transform (base 10), masked or clippedrS   rT   r0   NrY   r   i  )rZ   r[   r_   rO   )r   ra   rb   r   r   r   r<     s    0z#LogitTransform.transform_non_affinec                 C   s
   t | jS r:   )LogisticTransformr   r   r   r   r   r=     s    zLogitTransform.invertedc                 C   s   d t| j| jS Nz{}({!r})rP   rQ   r   r   r   r   r   r   rR     s    zLogitTransform.__str__)rJ   
r   r    r!   r>   r?   r   r<   r=   rR   r@   r   r   r8   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 )r   r0   rJ   c                    s   t    || _d S r:   )r1   r   r   r   r8   r   r   r     s    
zLogisticTransform.__init__c                 C   s   ddd|    S )zlogistic transform (base 10)rs   r0   rX   r   rf   r   r   r   r<     s    z&LogisticTransform.transform_non_affinec                 C   s
   t | jS r:   )r   r   r   r   r   r   r=     s    zLogisticTransform.invertedc                 C   s   d t| j| jS r   r   r   r   r   r   rR     s    zLogisticTransform.__str__)rJ   r   r   r   r8   r   r     s
   r   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[.
    logitrJ   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   rC   _use_overline	_one_half)r   r   rL   r   r   r   r   r   r     s    
zLogitScale.__init__c                 C   s   | j S )z8Return the `.LogitTransform` associated with this scale.rF   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 )Nr   T)minor)r   r   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   r0   rl   r   r   r   r   r   -  s
    
z LogitScale.limit_range_for_scaleN)rJ   )	r   r    r!   r"   r.   r   r   r   r   r   r   r   r   r     s   r   )r$   r]   r   r   rB   rp   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i |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_deprecatedrN   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   sP   g } t  D ]8\}}t|jp"d}| d|dt|ddg qd| S )zF
    Helper function for generating docstrings related to scales.
     z    z        
)	r   itemsinspectgetdocr   extendtextwrapindentjoin)Z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  rk   r   )Z
scale_typeZ
scale_docs)1r"   r   r   ZnumpyrZ   r   Z
matplotlibr,   r   r   Zmatplotlib.tickerr   r   r   r   r	   r
   r   r   r   r   Zmatplotlib.transformsr   r   r   r#   r/   rA   rG   rc   rg   ro   rr   r}   r   r   r   r   r   r   r   r   mapr   r   r   Zinterpdupdaterstripr   r   r   r   <module>   sR   0<"$*)1& 7@
