o
    zôjn(  ã                   @   sÒ   d Z ddlmZ ddlZddlmZmZ ddlmZ	 ddl
mZ ddlmZ ddlmZ ddlmZ ejd	 Zd
d„ ZG dd„ deƒZeeƒ ƒZeƒ  e¡ eeƒZeeƒZejdddd�ddd„ƒZ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.

  :ref:`colormap-manipulation` for examples of how to make
  colormaps.

  :ref:`colormaps` an in-depth discussion of choosing
  colormaps.

  :ref:`colormapnorms` for more details about data normalization.
é    )ÚMappingN)Ú_apiÚcolors)Ú_ScalarMappable)Údatad)Úcmaps)Úcmap_familiesz	image.lutc                  C   s¾   i t ¥} t ¡ D ]%\}}d|v rt ||t¡nd|v r#t |d |¡ntj ||t¡| |< qdddddœ}| ¡ D ]\}}| |  ¡ }||_	|| |< q9t
|  ¡ ƒD ]}| ¡ }|| |j	< qQ| S )zw
    Generate a dict mapping standard colormap names to standard colormaps, as
    well as the reversed colormaps.
    ÚredÚlistedÚgrayÚ	gist_grayÚ	gist_yargÚGreys)ÚgreyZ	gist_greyZ	gist_yergZGrays)Úcmaps_listedr   Úitemsr   ÚLinearSegmentedColormapÚ_LUTSIZEÚListedColormapÚ	from_listÚcopyÚnameÚlistÚvaluesÚreversed)Zcmap_dr   ÚspecÚaliasesÚaliasÚoriginal_nameÚcmapZrmap© r    ú^/var/www/html/academy/tools/voices/clone/sv-venv/lib/python3.10/site-packages/matplotlib/cm.pyÚ_gen_cmap_registry    s*   ÿÿû
û
r"   c                   @   s`   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d„ ZdS )ÚColormapRegistryaç  
    Container for colormaps that are known to Matplotlib by name.

    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)

    To get a list of all registered colormaps, you can do::

        from matplotlib import colormaps
        list(colormaps)
    c                 C   s   || _ t|ƒ| _d S ©N)Ú_cmapsÚtupleÚ_builtin_cmaps)Úselfr   r    r    r!   Ú__init__Z   s   zColormapRegistry.__init__c                 C   s0   z| j |  ¡ W S  ty   t|›d�ƒd ‚w )Nz is not a known colormap name)r%   r   ÚKeyError)r(   Úitemr    r    r!   Ú__getitem__^   s
   ÿzColormapRegistry.__getitem__c                 C   ó
   t | jƒS r$   )Úiterr%   ©r(   r    r    r!   Ú__iter__d   ó   
zColormapRegistry.__iter__c                 C   r-   r$   )Úlenr%   r/   r    r    r!   Ú__len__g   r1   zColormapRegistry.__len__c                 C   s   dd  dd„ | D ƒ¡ S )Nz'ColormapRegistry; available colormaps:
z, c                 s   s   � | ]	}d |› d �V  qdS )ú'Nr    )Ú.0r   r    r    r!   Ú	<genexpr>l   s   € z+ColormapRegistry.__str__.<locals>.<genexpr>)Újoinr/   r    r    r!   Ú__str__j   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__n   s   zColormapRegistry.__call__NF)r   Úforcec                C   s”   t jtj|d� |p|j}|| v r1|std|› d�ƒ‚|| jv r(td|›d�ƒ‚t  d|›d�¡ | ¡ | j	|< | j	| j|krH|| j	| _dS 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'   Úwarn_externalr   r%   )r(   r   r   r:   r    r    r!   Úregisterx   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'   r>   r%   Úpop)r(   r   r    r    r!   Ú
unregisterª   s   
zColormapRegistry.unregisterc                 C   sf   |du r| t jd  S t|tjƒr|S t|tƒr%tjtt	ƒ|d� | | S t
dd|›dt|ƒ› � ƒ‚)a€  
        Return a color map specified through *cmap*.

        Parameters
        ----------
        cmap : str or `~matplotlib.colors.Colormap` or None

            - if a `.Colormap`, return it
            - if a string, look it up in ``mpl.colormaps``
            - if None, return the Colormap defined in :rc:`image.cmap`

        Returns
        -------
        Colormap
        Nú
image.cmapr;   z<get_cmap expects None or an instance of a str or Colormap . zyou passed z	 of type )ÚmplÚrcParamsÚ
isinstancer   r=   Ústrr   Úcheck_in_listÚsortedÚ
_colormapsÚ	TypeErrorÚtype)r(   r   r    r    r!   Úget_cmapÊ   s   
ÿÿzColormapRegistry.get_cmap)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r)   r,   r0   r3   r8   r9   r@   rB   rM   r    r    r    r!   r#   B   s    
2 r#   z3.7z3.11z^``matplotlib.colormaps[name]`` or ``matplotlib.colormaps.get_cmap()`` or ``pyplot.get_cmap()``)ÚremovalÚalternativec                 C   sR   | du r	t jd } t| tjƒr| S tjttƒ| d� |du r"t|  S t|   	|¡S )ah  
    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
    NrC   )r   )
rD   rE   rF   r   r=   r   rH   rI   rJ   Ú	resampled)r   Úlutr    r    r!   rM   ù   s   
rM   c                 C   sJ   t | tjƒr| S | dur| ntjd }|tvr tjttƒ|d� tj	| S )ao  
    Ensure that we have a `.Colormap` object.

    For internal use to preserve type stability of errors.

    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

    NrC   r;   )
rF   r   r=   rD   rE   rJ   r   rH   rI   Ú	colormaps)r   Z	cmap_namer    r    r!   Ú_ensure_cmap  s   
rW   )NN) rQ   Úcollections.abcr   Ú
matplotlibrD   r   r   Zmatplotlib.colorizerr   ZScalarMappableZmatplotlib._cmr   Zmatplotlib._cm_listedr   r   Zmatplotlib._cm_multivarr   Zmultivar_cmapsZmatplotlib._cm_bivarZbivar_cmapsrE   r   r"   r#   rJ   ÚglobalsÚupdateÚ_multivar_colormapsÚ_bivar_colormapsÚ
deprecatedrM   rW   r    r    r    r!   Ú<module>   s0    
" 
-ý