
    gS`                     T   d Z ddlZddlZddlmZ ddlmZmZmZm	Z	m
Z
 ddlZej                  j                  j                  d        G d d      Z G d	 d
      Z G d de      Zej                  j                  j                  ddd        G d dee
j$                        Zd Zy)aN  
The Colorizer class which handles the data to color pipeline via a
normalization and a colormap.

.. admonition:: Provisional status of colorizer

    The ``colorizer`` module and classes in this file are considered
    provisional and may change at any time without a deprecation period.

.. seealso::

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

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

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

  :ref:`colormapnorms` for more details about data normalization.

    N)ma)_apicolorscbookscaleartistzcolorizer : `~matplotlib.colorizer.Colorizer` or None, default: None
    The Colorizer object used to map color to data. If None, a Colorizer
    object is created from a *norm* and *cmap*.)colorizer_docc                   b   e Zd ZdZddZd Zed        Zej                  d        ZddZ	e
dd       Zd	 Zd
 Zd Zed        Zej                  d        ZddZd Zd Zed        Zej                  d        Zed        Zej                  d        Zed        Zej                  d        Zy)	Colorizera  
    Data to color pipeline.

    This pipeline is accessible via `.Colorizer.to_rgba` and executed via
    the `.Colorizer.norm` and `.Colorizer.cmap` attributes.

    Parameters
    ----------
    cmap: colorbar.Colorbar or str or None, default: None
        The colormap used to color data.

    norm: colors.Normalize or str or None, default: None
        The normalization used to normalize the data
    Nc                     d | _         | j                  |       d | _        d | _        || _        t        j                  dg      | _        d | _        y )Nchangedsignals)	_cmap	_set_cmap_id_norm_normnormr   CallbackRegistry	callbackscolorbar)selfcmapr   s      Q/var/www/dash_apps/app1/venv/lib/python3.12/site-packages/matplotlib/colorizer.py__init__zColorizer.__init__5   sE    
t
	//D    c                     ||7| j                  ||       t        |t        j                        rt	        d      | j                  |       y)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_clim
isinstancer   	Normalize
ValueErrorautoscale_None)r   r   vminvmaxAs        r   _scale_normzColorizer._scale_normA   sO     t/MM$%$ 0 01 => > 	Ar   c                     | j                   S N)r   r   s    r   r   zColorizer.normW       zzr   c                    t        j                  t        j                  t        d f|       |t        j                         }n4t        |t              r$	 t        j                  |   } t        |             }|| j                  u ry | j                  d u }|s/| j                  j                  j                  | j                         || _        | j                  j                  j#                  d| j$                        | _        |s| j%                          y y # t        $ r- t        ddj                  t        j                               d w xY w)Nr   z;Invalid norm str name; the following values are supported: , r   )r   check_isinstancer   r    strr   r   _scale_mappingKeyErrorr!   join_auto_norm_from_scaler   r   
disconnectr   r   connectr   )r   r   	scale_clsin_inits       r   r   zColorizer.norm[   s    v//d;$G<##%Dc"!006	 4(35D499))t#II**4==9
		++33I48LLBLLN %   ""&))E,@,@"A!BD s   D 6Ec                     t        |t        j                        r#|j                  dk(  r| j	                  ||||      S t        j                  |      }|r| j                  |      }| j                  |||      }|S )  
        Return a normalized RGBA array corresponding to *x*.

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

        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 `~numpy.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 `~numpy.uint8`, or it can be floats with
        values in the 0-1 range; otherwise a ValueError will be raised.
        Any NaNs or masked elements will be set to 0 alpha.
        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 `~numpy.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).

           )alphabytes)	r   npndarrayndim_pass_image_datar   asarrayr   r   )r   xr;   r<   r   rgbas         r   to_rgbazColorizer.to_rgbax   sk    > a$1((E5$?? JJqM		!Ayy%uy5r   c                    | j                   d   dk(  r|d}| j                  t        j                  k(  rt        j                  |dz        }| j                   dd \  }}t        j                  ||df| j                        }| |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(  rt        j                  t        j                  |       x}      r@| j                   d   dk(  r|j                         }d
|t        j                  |d      ddf<   |r1|j                         dkD  s|j                         d
k  rt        d      |r}|dz  j                  t        j                        }nZ|j                  t        j                  k(  r%|s;|j                  t        j                        dz  }nt        d|j                  z        t        j                  j                  |       r9d
|t        j                  t        j                  j!                  |       d      df<   |S )z
        Helper function to pass ndarray of shape (...,3) or (..., 4)
        through `to_rgba()`, see `to_rgba()` for docstring.
           r:   N         )shapedtypezThird dimension must be 3 or 4fr   )axisz:Floating point image RGB values must be in the 0..1 range.z9Image RGB array must be uint8 or floating point; found %s)rJ   rK   r=   uint8emptyr!   kindanyisnancopymaxminastypefloat32r   	is_maskedgetmaskarray)rB   r;   r<   r   mnxxnanss           r   r@   zColorizer._pass_image_data   s    771:?}ww"(("-772A;DAqAq	9BBq!RaRxLBq!QwKWWQZ1_B=>>88==Cvvbhhqk)d*771:?B./266$Q'*+AA  "> ? ?3h&&rxx0XX!YYrzz*S0 8:<((C D D 55??1;<Brvvbee((+!4a78	r   c                 T    |t        d      | j                  j                  |       y)b
        Autoscale the scalar limits on the norm instance using the
        current array
        N%You must first set_array for mappable)	TypeErrorr   	autoscaler   r%   s     r   rb   zColorizer.autoscale   s)    
 9CDD 			Ar   c                 T    |t        d      | j                  j                  |       y)
        Autoscale the scalar limits on the norm instance using the
        current array, changing only limits that are None
        Nr`   )ra   r   r"   rc   s     r   r"   zColorizer.autoscale_None   s)    
 9CDD 			  #r   c                 ~    ddl m} | j                  du }|j                  |      | _        |s| j	                          yy)
        Set the colormap for luminance data.

        Parameters
        ----------
        cmap : `.Colormap` or str or None
        r   )cmN)
matplotlibrh   r   _ensure_cmapr   )r   r   rh   r7   s       r   r   zColorizer._set_cmap   s6     	"**$__T*
LLN r   c                     | j                   S r(   )r   r)   s    r   r   zColorizer.cmap   r*   r   c                 &    | j                  |       y r(   )r   r   r   s     r   r   zColorizer.cmap   s    tr   c                     |	 |\  }}|$t        j                  |      | j                  _        |%t        j                  |      | j                  _        yy# t         t        f$ r Y _w xY w)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)ra   r!   r   _sanitize_extremar   r#   r$   r   r#   r$   s      r   r   zColorizer.set_clim   so      <!
d #55d;DIIN#55d;DIIN 	 z* s   A A)(A)c                 Z    | j                   j                  | j                   j                  fS zV
        Return the values (min, max) that are mapped to the colormap limits.
        )r   r#   r$   r)   s    r   get_climzColorizer.get_clim  s     yy~~tyy~~--r   c                 H    | j                   j                  d       d| _        yz
        Call this whenever the mappable is changed to notify all the
        callbackSM listeners to the 'changed' signal.
        r   TNr   processstaler)   s    r   r   zColorizer.changed  s    
 	y)
r   c                 (    | j                         d   S )Nr   rs   r)   s    r   r#   zColorizer.vmin!      }}q!!r   c                 (    | j                  |       y )N)r#   r   )r   r#   s     r   r#   zColorizer.vmin%      4 r   c                 (    | j                         d   S NrG   rz   r)   s    r   r$   zColorizer.vmax)  r{   r   c                 (    | j                  |       y )N)r$   r}   )r   r$   s     r   r$   zColorizer.vmax-  r~   r   c                 .    | j                   j                  S r(   r   clipr)   s    r   r   zColorizer.clip1  s    yy~~r   c                 &    || j                   _        y r(   r   )r   r   s     r   r   zColorizer.clip5  s    		r   NNNFT)__name__
__module____qualname____doc__r   r&   propertyr   setterrD   staticmethodr@   rb   r"   r   r   r   rs   r   r#   r$   r    r   r   r   r   &   s&   
,   
[[ 8'R ( (T		$   
[[ <4. " " 
[[! ! " " 
[[! !   
[[ r   r   c                        e Zd ZdZd ZddZd ZddZ fdZe	d        Z
e
j                  d        Z
d	 Zd
 Ze	d        Zej                  d        Zd Zd Zd Ze	d        Zej                  d        Zd Z xZS )_ColorizerInterfaceaB  
    Base class that contains the interface to `Colorizer` objects from
    a `ColorizingArtist` or `.cm.ScalarMappable`.

    Note: This class only contain functions that interface the .colorizer
    attribute. Other functions that as shared between `.ColorizingArtist`
    and `.cm.ScalarMappable` are not included.
    c                 T    | j                   j                  |||| j                         y r(   )
_colorizerr&   _A)r   r   r#   r$   s       r   r&   z_ColorizerInterface._scale_normC  s    ##D$dgg>r   c                 @    | j                   j                  ||||      S )r9   )r;   r<   r   )r   rD   )r   rB   r;   r<   r   s        r   rD   z_ColorizerInterface.to_rgbaF  s"    < &&qU&NNr   c                 6    | j                   j                         S rr   )r   rs   r)   s    r   rs   z_ColorizerInterface.get_climf  s     ''))r   c                 <    | j                   j                  ||       y)aO  
        Set the norm limits for image scaling.

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

             For scalar data, the limits may also be passed as a
             tuple (*vmin*, *vmax*) as a single positional argument.

             .. ACCEPTS: (vmin: float, vmax: float)
        N)r   r   rp   s      r   r   z_ColorizerInterface.set_climl  s      	  t,r   c                 @    	 t         |          S # t        $ r Y yw xY wr   )super	get_alphaAttributeError)r   	__class__s    r   r   z_ColorizerInterface.get_alpha~  s(    	7$&& 		s    	c                 .    | j                   j                  S r(   r   r   r)   s    r   r   z_ColorizerInterface.cmap      ###r   c                 &    || j                   _        y r(   r   rm   s     r   r   z_ColorizerInterface.cmap      #r   c                 .    | j                   j                  S )z Return the `.Colormap` instance.r   r)   s    r   get_cmapz_ColorizerInterface.get_cmap  r   r   c                     || _         y)rg   N)r   rm   s     r   set_cmapz_ColorizerInterface.set_cmap  s     	r   c                 .    | j                   j                  S r(   r   r   r)   s    r   r   z_ColorizerInterface.norm  r   r   c                 &    || j                   _        y r(   r   r   r   s     r   r   z_ColorizerInterface.norm  r   r   c                     || _         y)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   s     r   set_normz_ColorizerInterface.set_norm  s     	r   c                 N    | j                   j                  | j                         y)r_   N)r   rb   r   r)   s    r   rb   z_ColorizerInterface.autoscale  s    
 	!!$''*r   c                 N    | j                   j                  | j                         y)re   N)r   r"   r   r)   s    r   r"   z"_ColorizerInterface.autoscale_None  s    
 	&&tww/r   c                 .    | j                   j                  S )zL
        The last colorbar associated with this object. May be None
        r   r   r)   s    r   r   z_ColorizerInterface.colorbar  s    
 '''r   c                 &    || j                   _        y r(   r   )r   r   s     r   r   z_ColorizerInterface.colorbar  s    #+ r   c                    | j                   j                  }t        j                  j	                  |      ry| j                  |      }t        j                  |      rt        | j
                  t        j                        rt        j                  t        j                  | j
                  j                  |z
              }t        d|dz
        }t        j                  | j
                  j                  ||dz          j                         }n| j
                  j                  | j
                  j                   k(  r-t        j                  | j
                  j                  dz        }n^| j
                  j#                  t%        ||z        t        j&                  ddg      z   |z        }t        ||z
        j                         }t)        j*                  ||      }nd}d|d| d	d
S )Nz[]r   rG   rF   g?r:   [z-#.g])r   Nr=   r   getmaskr   isfiniter   r   BoundaryNormargminabs
boundariesrT   diffr#   r$   inverseintarrayr   _g_sig_digits)	r   datar[   normedcur_idx	neigh_idxdelta	neighborsg_sig_digitss	            r   _format_cursor_data_overridez0_ColorizerInterface._format_cursor_data_override  sn    IIKK55==4;;v$))V%8%89))BFF499+?+?$+F$GH7Q;/	II((7Q;?#%  499>>1tyy~~23 !II--!_rxxA'771<>	I,-113 ..tU;LL4L>*+1--r   r   r   )r   r   r   r   r&   rD   rs   r   r   r   r   r   r   r   r   r   rb   r"   r   r   __classcell__r   s   @r   r   r   :  s    ?O@*-$ $ $ 
[[$ $$ $ $ 
[[$ $ +0 ( ( __, ,!.r   r   c                   \     e Zd ZdZd
dd fdZd Zd Zd Zed        Z	ed	        Z
 xZS )_ScalarMappablez
    A mixin class to map one or multiple sets of scalar data to RGBA.

    The ScalarMappable applies data normalization before returning RGBA colors from
    the given `~matplotlib.colors.Colormap`.
    N	colorizerc                   t        |   di | d| _        | j                  |||      | _        d| _        | j                  j                  j                  d| j                        | _	        t        j                  dg      | _        y)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)r   r   r   r   r   r   )r   r   r   _get_colorizerr   r   r   r5   r   _id_colorizerr   r   )r   r   r   r   kwargsr   s        r   r   z_ScalarMappable.__init__  st     	"6"--	SW-X!__66>>y$,,W//Dr   c                 <   |d| _         yt        j                  |d      }t        j                  |j
                  t        d      st        d|j
                   d      || _         | j                  j                         s| j                  j                  |       yy)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)rS   	same_kindzImage data of dtype z cannot be converted to float)r   r   safe_masked_invalidr=   can_castrK   floatra   r   scaledr   r"   rc   s     r   	set_arrayz_ScalarMappable.set_array  s     9DG%%ad3{{177E;72177) <1 1 2 2 yy!OO**1- "r   c                     | 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.
        )r   r)   s    r   	get_arrayz_ScalarMappable.get_array4  s     wwr   c                 J    | j                   j                  d|        d| _        yru   rv   r)   s    r   r   z_ScalarMappable.changed=  s    
 	y$/
r   c                     | \t        |j                         D cg c]  }|du c}      r2t        ddj                  d |j	                         D              z         yyc c}w )zZ
        Raises a ValueError if any kwarg is not None while colorizer is not None
        NzZThe `colorizer` keyword cannot be used simultaneously with any of the following keywords: r-   c              3   (   K   | ]
  }d | d   yw)`Nr   ).0keys     r   	<genexpr>z?_ScalarMappable._check_exclusionary_keywords.<locals>.<genexpr>N  s     ,QCqQZ,Qs   )rQ   valuesr!   r2   keys)r   r   vals      r   _check_exclusionary_keywordsz,_ScalarMappable._check_exclusionary_keywordsE  sh    
  v}}?CtO?@  "I#'99,Q6;;=,Q#Q"R S S A !?s   A c                 v    t        |t              rt        j                  t        | |       |S t        | |      S )N)r   r   )r   r   r   r   )r   r   r   s      r   r   z_ScalarMappable._get_colorizerP  s;    i+884 9  t$$r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   s   @r   r   r     sO    *E$ E,.2 S S % %r   r   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 :ref:`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).)cmap_docnorm_docvmin_vmax_docc                   \     e Zd ZdZ fdZed        Zej                  d        Zd Z xZ	S )ColorizingArtistz
    Base class for artists that make map data to color using a `.colorizer.Colorizer`.

    The `.colorizer.Colorizer` applies data normalization before
    returning RGBA colors from a `~matplotlib.colors.Colormap`.

    c                 ^    t        j                  t        |       t        |   dd|i| y)zZ
        Parameters
        ----------
        colorizer : `.colorizer.Colorizer`
        r   r   Nr   )r   r.   r   r   r   )r   r   r   r   s      r   r   zColorizingArtist.__init__  s*     	i9=7977r   c                     | j                   S r(   )r   r)   s    r   r   zColorizingArtist.colorizer  s    r   c                     t        j                  t        |       | j                  j                  j                  | j                         || _        |j                  j                  d| j                        | _        y )Nr   r   )	r   r.   r   r   r   r4   r   r5   r   )r   cls     r   r   zColorizingArtist.colorizer  sT    i26!!,,T-?-?@\\11)T\\Jr   c                 8     | j                   |fi | || _        y)z[
        Raises a ValueError if any kwarg is not None while colorizer is not None.
        N)r   r   )r   r   r   s      r   _set_colorizer_check_keywordsz.ColorizingArtist._set_colorizer_check_keywords  s      	*)))>v>"r   )
r   r   r   r   r   r   r   r   r   r   r   s   @r   r   r   w  sB    8   K K#r   r   c                 .   	   t        j                  t        j                  | d            t         j                               }t        |      S # t
        $ r;   t        j                  |       t         j                               }Y t        |      S w xY w)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partialr    ra   type)r6   r   s     r   r3   r3     s    $  >v**iV<>   :   5v**95  : s   AA 7BB)r   r   numpyr=   r   ri   r   r   r   r   r   mpl
_docstringinterpdregisterr   r   r   Artistr   r3   r   r   r   <module>r      s   *    9 9      3   Q Qhr. r.jh%) h%V     8'   :!# !#Hr   