a
    Sic\`                     @   s>  d Z ddlm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
mZmZ ddlmZ ddlmZ e	jG dd	 d	Zejd
 Zdd ZG dd deZee Ze e e	jddddd)ddddZd*ddZe	jdddddeZe	jdddddd Zdd  Z G d!d" d"Z!ej"j#jd#d$d%d& d'd( Z$dS )+a  
Builtin colormaps, colormap handling utilities, and the `ScalarMappable` mixin.

.. seealso::

  :doc:`/gallery/color/colormap_reference` for a list of builtin colormaps.

  :doc:`/tutorials/colors/colormap-manipulation` for examples of how to
  make colormaps.

  :doc:`/tutorials/colors/colormaps` an in-depth discussion of
  choosing colormaps.

  :doc:`/tutorials/colors/colormapnorms` for more details about data
  normalization.
    )MappingN)ma)_apicolorscbookscale)datad)cmapsc                   @   s(   e Zd Zejddddedd ZdS )__getattr__3.5 zrcParams['image.lut'])obj_typealternativec                 C   s   t S N)_LUTSIZEself r   I/var/www/html/django/DPS/env/lib/python3.9/site-packages/matplotlib/cm.py<lambda>"       z__getattr__.<lambda>N)__name__
__module____qualname__r   
deprecatedpropertyZLUTSIZEr   r   r   r   r
      s
   
r
   z	image.lutc                  C   s   i t } t D ]J\}}d|v r.t||tn&d|v rFt|d |ntj||t| |< qt| 	 D ]}|
 }|| |j< qh| S )zw
    Generate a dict mapping standard colormap names to standard colormaps, as
    well as the reversed colormaps.
    redlisted)cmaps_listedr   itemsr   LinearSegmentedColormapr   ListedColormap	from_listlistvaluesreversedname)Zcmap_dr&   speccmapZrmapr   r   r   _gen_cmap_registry(   s    r)   c                   @   sX   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dddddZ
dd ZdS )ColormapRegistryaJ  
    Container for colormaps that are known to Matplotlib by name.

    .. admonition:: Experimental

       While we expect the API to be final, we formally mark it as
       experimental for 3.5 because we want to keep the option to still adapt
       the API for 3.6 should the need arise.

    The universal registry instance is `matplotlib.colormaps`. There should be
    no need for users to instantiate `.ColormapRegistry` themselves.

    Read access uses a dict-like interface mapping names to `.Colormap`\s::

        import matplotlib as mpl
        cmap = mpl.colormaps['viridis']

    Returned `.Colormap`\s are copies, so that their modification does not
    change the global definition of the colormap.

    Additional colormaps can be added via `.ColormapRegistry.register`::

        mpl.colormaps.register(my_colormap)
    c                 C   s   || _ t|| _d| _d S )NF)_cmapstuple_builtin_cmaps_allow_override_builtin)r   r	   r   r   r   __init__U   s    
zColormapRegistry.__init__c                 C   s8   z| j |  W S  ty2   t|dd Y n0 d S )Nz is not a known colormap name)r+   copyKeyError)r   itemr   r   r   __getitem__[   s    zColormapRegistry.__getitem__c                 C   s
   t | jS r   )iterr+   r   r   r   r   __iter__a   s    zColormapRegistry.__iter__c                 C   s
   t | jS r   )lenr+   r   r   r   r   __len__d   s    zColormapRegistry.__len__c                 C   s   dd dd | D  S )Nz'ColormapRegistry; available colormaps:
, c                 s   s   | ]}d | d V  qdS )'Nr   ).0r&   r   r   r   	<genexpr>i   r   z+ColormapRegistry.__str__.<locals>.<genexpr>)joinr   r   r   r   __str__g   s    zColormapRegistry.__str__c                 C   s   t | S )z
        Return a list of the registered colormap names.

        This exists only for backward-compatibility in `.pyplot` which had a
        ``plt.colormaps()`` method. The recommended way to get this list is
        now ``list(colormaps)``.
        )r#   r   r   r   r   __call__k   s    zColormapRegistry.__call__NFr&   forcec                C   s|   t jtj|d |p|j}|| v rj|s8td| dn || jv rX| jsXtd|dt d|d |	 | j
|< dS )	a  
        Register a new colormap.

        The colormap name can then be used as a string argument to any ``cmap``
        parameter in Matplotlib. It is also available in ``pyplot.get_cmap``.

        The colormap registry stores a copy of the given colormap, so that
        future changes to the original colormap instance do not affect the
        registered colormap. Think of this as the registry taking a snapshot
        of the colormap at registration.

        Parameters
        ----------
        cmap : matplotlib.colors.Colormap
            The colormap to register.

        name : str, optional
            The name for the colormap. If not given, ``cmap.name`` is used.

        force : bool, default: False
            If False, a ValueError is raised if trying to overwrite an already
            registered name. True supports overwriting registered colormaps
            other than the builtin colormaps.
        r(   zA colormap named "z" is already registered.z Re-registering the builtin cmap z is not allowed.zOverwriting the cmap z" that was already in the registry.N)r   check_isinstancer   Colormapr&   
ValueErrorr-   r.   warn_externalr0   r+   )r   r(   r&   r@   r   r   r   registeru   s    



zColormapRegistry.registerc                 C   s,   || j v rtd|d| j|d dS )a  
        Remove a colormap from the registry.

        You cannot remove built-in colormaps.

        If the named colormap is not registered, returns with no error, raises
        if you try to de-register a default colormap.

        .. warning::

            Colormap names are currently a shared namespace that may be used
            by multiple packages. Use `unregister` only if you know you
            have registered that name before. In particular, do not
            unregister just in case to clean the name before registering a
            new colormap.

        Parameters
        ----------
        name : str
            The name of the colormap to be removed.

        Raises
        ------
        ValueError
            If you try to remove a default built-in colormap.
        zcannot unregister z which is a builtin colormap.N)r-   rD   r+   pop)r   r&   r   r   r   
unregister   s    
zColormapRegistry.unregister)r   r   r   __doc__r/   r3   r5   r7   r=   r>   rF   rH   r   r   r   r   r*   <   s   
/r*   z3.6Tz'``matplotlib.colormaps.register(name)``)pendingr   F)override_builtinc             
   C   st   t jtdf| d | du rTz
|j} W n. tyR } ztd|W Y d}~n
d}~0 0 |t_tj|| |d dt_dS )a  
    Add a colormap to the set recognized by :func:`get_cmap`.

    Register a new colormap to be accessed by name ::

        LinearSegmentedColormap('swirly', data, lut)
        register_cmap(cmap=swirly_cmap)

    Parameters
    ----------
    name : str, optional
       The name that can be used in :func:`get_cmap` or :rc:`image.cmap`

       If absent, the name will be the :attr:`~matplotlib.colors.Colormap.name`
       attribute of the *cmap*.

    cmap : matplotlib.colors.Colormap
       Despite being the second argument and having a default value, this
       is a required argument.

    override_builtin : bool

        Allow built-in colormaps to be overridden by a user-supplied
        colormap.

        Please do not use this unless you are sure you need it.
    Nr&   z+Arguments must include a name or a Colormapr?   F)	r   rB   strr&   AttributeErrorrD   
_colormapsr.   rF   )r&   r(   rK   errr   r   r   register_cmap   s    !
rQ   c                 C   sV   | du rt jd } t| tjr"| S tjtt| d |du rDt|  S t|  	|S dS )ag  
    Get a colormap instance, defaulting to rc values if *name* is None.

    Parameters
    ----------
    name : `matplotlib.colors.Colormap` or str or None, default: None
        If a `.Colormap` instance, it will be returned. Otherwise, the name of
        a colormap known to Matplotlib, which will be resampled by *lut*. The
        default, None, means :rc:`image.cmap`.
    lut : int or None, default: None
        If *name* is not already a Colormap instance and *lut* is not None, the
        colormap will be resampled to have *lut* entries in the lookup table.

    Returns
    -------
    Colormap
    N
image.cmaprL   )
mplrcParams
isinstancer   rC   r   check_in_listsortedrO   	resampled)r&   lutr   r   r   	_get_cmap   s    
rZ   get_cmapz``matplotlib.colormaps[name]``)r&   rJ   r   z)``matplotlib.colormaps.unregister(name)``c                 C   s   t | d}t |  |S )aY  
    Remove a colormap recognized by :func:`get_cmap`.

    You may not remove built-in colormaps.

    If the named colormap is not registered, returns with no error, raises
    if you try to de-register a default colormap.

    .. warning::

      Colormap names are currently a shared namespace that may be used
      by multiple packages. Use `unregister_cmap` only if you know you
      have registered that name before. In particular, do not
      unregister just in case to clean the name before registering a
      new colormap.

    Parameters
    ----------
    name : str
        The name of the colormap to be un-registered

    Returns
    -------
    ColorMap or None
        If the colormap was registered, return it if not return `None`

    Raises
    ------
    ValueError
       If you try to de-register a default built-in colormap.
    N)rO   getrH   )r&   r(   r   r   r   unregister_cmap   s    %
r]   c                 C   sN   z t tj| ddt j }W n$ tyD   t | t j }Y n0 t|S )a  
    Automatically generate a norm class from *scale_cls*.

    This differs from `.colors.make_norm_from_scale` in the following points:

    - This function is not a class decorator, but directly returns a norm class
      (as if decorating `.Normalize`).
    - The scale is automatically constructed with ``nonpositive="mask"``, if it
      supports such a parameter, to work around the difference in defaults
      between standard scales (which use "clip") and norms (which use "mask").

    Note that ``make_norm_from_scale`` caches the generated norm classes
    (not the instances) and reuses them for later calls.  For example,
    ``type(_auto_norm_from_scale("log")) == LogNorm``.
    mask)nonpositive)r   make_norm_from_scale	functoolspartial	Normalize	TypeErrortype)	scale_clsnormr   r   r   _auto_norm_from_scaleJ  s    
rh   c                   @   s   e Zd ZdZd)ddZejdddedd	 Zd
d Z	d*ddZ
dd Zdd Zdd Zdd Zd+ddZdd Zdd Zedd Zejd d Zd!d" Zd#d$ Zd%d& Zd'd( ZdS ),ScalarMappablez
    A mixin class to map scalar data to RGBA.

    The ScalarMappable applies data normalization before returning RGBA colors
    from the given colormap.
    Nc                 C   s@   d| _ d| _| | d| _| | d| _tjdgd| _dS )ar  
        Parameters
        ----------
        norm : `.Normalize` (or subclass thereof) or str or None
            The normalizing object which scales data, typically into the
            interval ``[0, 1]``.
            If a `str`, a `.Normalize` subclass is dynamically generated based
            on the scale with the corresponding name.
            If *None*, *norm* defaults to a *colors.Normalize* object which
            initializes its scaling based on the first data processed.
        cmap : str or `~matplotlib.colors.Colormap`
            The colormap used to map normalized data values to RGBA colors.
        Nchanged)signals)	_A_normset_normr(   set_cmapZcolorbarr   CallbackRegistry	callbacks)r   rg   r(   r   r   r   r/   n  s    

zScalarMappable.__init__r   rq   )r   c                 C   s   | j S r   )rq   r   r   r   r   r     r   zScalarMappable.<lambda>c                 C   s<   |dus|dur0|  || t|tjr0td|   dS )a,  
        Helper for initial scaling.

        Used by public functions that create a ScalarMappable and support
        parameters *vmin*, *vmax* and *norm*. This makes sure that a *norm*
        will take precedence over *vmin*, *vmax*.

        Note that this method does not set the norm.
        NzPassing a Normalize instance simultaneously with vmin/vmax is not supported.  Please pass vmin/vmax directly to the norm when creating it.)set_climrU   r   rc   rD   autoscale_None)r   rg   vminvmaxr   r   r   _scale_norm  s    
zScalarMappable._scale_normFTc           	      C   s  z>|j dkr>|jd dkr|du r*d}|jtjkrDt|d }|jdd \}}tj||df|jd}||ddddddf< ||dddddf< n|jd dkr|}ntd|jjd	kr|r| dks|	 d
k rtd|r8|d 
tj}n4|jtjkr*|s8|
tjd }ntd|j |W S W n tyT   Y n0 t|}|rp| |}| j|||d}|S )a  
        Return a normalized rgba array corresponding to *x*.

        In the normal case, *x* is a 1D or 2D sequence of scalars, and
        the corresponding ndarray of rgba values will be returned,
        based on the norm and colormap set for this ScalarMappable.

        There is one special case, for handling images that are already
        rgb or rgba, such as might have been read from an image file.
        If *x* is an ndarray with 3 dimensions,
        and the last dimension is either 3 or 4, then it will be
        treated as an rgb or rgba array, and no mapping will be done.
        The array can be uint8, or it can be floating point with
        values in the 0-1 range; otherwise a ValueError will be raised.
        If it is a masked array, the mask will be ignored.
        If the last dimension is 3, the *alpha* kwarg (defaulting to 1)
        will be used to fill in the transparency.  If the last dimension
        is 4, the *alpha* kwarg is ignored; it does not
        replace the preexisting alpha.  A ValueError will be raised
        if the third dimension is other than 3 or 4.

        In either case, if *bytes* is *False* (default), the rgba
        array will be floats in the 0-1 range; if it is *True*,
        the returned rgba array will be uint8 in the 0 to 255 range.

        If norm is False, no normalization of the input data is
        performed, and it is assumed to be in the range (0-1).

              N         )shapedtypezThird dimension must be 3 or 4fr   z:Floating point image RGB values must be in the 0..1 range.z9Image RGB array must be uint8 or floating point; found %s)alphabytes)ndimr|   r}   npuint8emptyrD   kindmaxminastypefloat32rN   r   asarrayrg   r(   )	r   xr   r   rg   mnxxrgbar   r   r   to_rgba  sB    


zScalarMappable.to_rgbac                 C   sL   |du rd| _ dS tj|dd}t|jtdsBtd|j d|| _ dS )aB  
        Set the value array from array-like *A*.

        Parameters
        ----------
        A : array-like or None
            The values that are mapped to colors.

            The base class `.ScalarMappable` does not make any assumptions on
            the dimensionality and shape of the value array *A*.
        NT)r0   	same_kindzImage data of dtype z cannot be converted to float)rl   r   safe_masked_invalidr   can_castr}   floatrd   )r   Ar   r   r   	set_array  s    zScalarMappable.set_arrayc                 C   s   | j S )z
        Return the array of values, that are mapped to colors.

        The base class `.ScalarMappable` does not make any assumptions on
        the dimensionality and shape of the array.
        )rl   r   r   r   r   	get_array  s    zScalarMappable.get_arrayc                 C   s   | j S )z Return the `.Colormap` instance.rA   r   r   r   r   r[     s    zScalarMappable.get_cmapc                 C   s   | j j| j jfS )zV
        Return the values (min, max) that are mapped to the colormap limits.
        )rg   rt   ru   r   r   r   r   get_clim  s    zScalarMappable.get_climc              	   C   s\   |du r,z|\}}W n t tfy*   Y n0 |durBt|| j_|durXt|| j_dS )a>  
        Set the norm limits for image scaling.

        Parameters
        ----------
        vmin, vmax : float
             The limits.

             The limits may also be passed as a tuple (*vmin*, *vmax*) as a
             single positional argument.

             .. ACCEPTS: (vmin: float, vmax: float)
        N)rd   rD   r   _sanitize_extremarg   rt   ru   )r   rt   ru   r   r   r   rr     s    zScalarMappable.set_climc                 C   s   dS )zU
        Returns
        -------
        float
            Always returns 1.
        g      ?r   r   r   r   r   	get_alpha(  s    zScalarMappable.get_alphac                 C   s$   | j du }t|| _ |s |   dS )z
        Set the colormap for luminance data.

        Parameters
        ----------
        cmap : `.Colormap` or str or None
        N)r(   _ensure_cmaprj   )r   r(   in_initr   r   r   ro   2  s    

zScalarMappable.set_cmapc                 C   s   | j S r   )rm   r   r   r   r   rg   @  s    zScalarMappable.normc              	   C   s   t jtjtd f|d |d u r(t }nNt|trvztj| }W n* tyj   t	d
dtjd Y n0 t| }|| ju rd S | jd u }|s| jj| j || _| jjd| j| _|s|   d S )Nrg   z=Invalid norm str name; the following values are supported: {}r8   rj   )r   rB   r   rc   rM   rU   r   _scale_mappingr1   rD   formatr<   rh   rg   rq   
disconnectZ_id_normrm   connectrj   )r   rg   rf   r   r   r   r   rg   D  s4    






c                 C   s
   || _ dS )a_  
        Set the normalization instance.

        Parameters
        ----------
        norm : `.Normalize` or str or None

        Notes
        -----
        If there are any colorbars using the mappable for this norm, setting
        the norm of the mappable will reset the norm, locator, and formatters
        on the colorbar to default.
        Nr   )r   rg   r   r   r   rn   a  s    zScalarMappable.set_normc                 C   s$   | j du rtd| j| j  dS )zb
        Autoscale the scalar limits on the norm instance using the
        current array
        N%You must first set_array for mappable)rl   rd   rg   	autoscaler   r   r   r   r   q  s    
zScalarMappable.autoscalec                 C   s$   | j du rtd| j| j  dS )z
        Autoscale the scalar limits on the norm instance using the
        current array, changing only limits that are None
        Nr   )rl   rd   rg   rs   r   r   r   r   rs   |  s    
zScalarMappable.autoscale_Nonec                 C   s   | j d|  d| _dS )z
        Call this whenever the mappable is changed to notify all the
        callbackSM listeners to the 'changed' signal.
        rj   TN)rq   processZstaler   r   r   r   rj     s    zScalarMappable.changed)NN)NFT)NN)r   r   r   rI   r/   r   r   r   ZcallbacksSMrv   r   r   r   r[   r   rr   r   ro   rg   setterrn   r   rs   rj   r   r   r   r   ri   f  s,   


F	



ri   zcmap : str or `~matplotlib.colors.Colormap`, default: :rc:`image.cmap`
    The Colormap instance or registered colormap name used to map scalar data
    to colors.a  norm : str or `~matplotlib.colors.Normalize`, optional
    The normalization method used to scale scalar data to the [0, 1] range
    before mapping to colors using *cmap*. By default, a linear scaling is
    used, mapping the lowest value to 0 and the highest to 1.

    If given, this can be one of the following:

    - An instance of `.Normalize` or one of its subclasses
      (see :doc:`/tutorials/colors/colormapnorms`).
    - A scale name, i.e. one of "linear", "log", "symlog", "logit", etc.  For a
      list of available scales, call `matplotlib.scale.get_scale_names()`.
      In that case, a suitable `.Normalize` subclass is dynamically generated
      and instantiated.a  vmin, vmax : float, optional
    When using scalar data and no explicit *norm*, *vmin* and *vmax* define
    the data range that the colormap covers. By default, the colormap covers
    the complete value range of the supplied data. It is an error to use
    *vmin*/*vmax* when a *norm* instance is given (but using a `str` *norm*
    name together with *vmin*/*vmax* is acceptable).)Zcmap_docZnorm_docZvmin_vmax_docc                 C   sB   t | tjr| S | dur| ntjd }tjtt|d tj	| S )a2  
    Ensure that we have a `.Colormap` object.

    Parameters
    ----------
    cmap : None, str, Colormap

        - if a `Colormap`, return it
        - if a string, look it up in mpl.colormaps
        - if None, look up the default color map in mpl.colormaps

    Returns
    -------
    Colormap
    NrR   rA   )
rU   r   rC   rS   rT   r   rV   rW   rO   	colormaps)r(   Z	cmap_namer   r   r   r     s
    r   )NN)NN)%rI   collections.abcr   ra   numpyr   r   
matplotlibrS   r   r   r   r   Zmatplotlib._cmr   Zmatplotlib._cm_listedr	   r   caching_module_getattrr
   rT   r   r)   r*   rO   globalsupdater   rQ   rZ   r[   r]   rh   ri   
_docstringinterpdr   r   r   r   r   <module>   sZ   
 
+

%  -