
    hW             
          S r SSKrSSKJrJrJr  SSKrSSKrSSKrSSK	r	SSK
r
SSKJr  SSKrSSKJr  SSKJr  SSKrSSKrSSKJrJrJrJrJr  SS	KJrJrJrJr   " S
 S\ 5      r!0 r"\"RG                  \5        \"RG                  \RH                  " 5        V Vs0 s H   u  pSU ;   d  M  U RK                  SS5      U_M"     snn 5        \"RG                  \5        \"RG                  \5        \"RG                  \RH                  " 5        V Vs0 s H   u  pSU ;   d  M  U RK                  SS5      U_M"     snn 5        \"RG                  \5        \!" \"5      r"Sr&Sr'S r( " S S\5      r)\)" 5       r*S r+\RX                  " S5      r-S r.S r/S r0S r1S r2SWS jr3SWS jr4SWS jr5S r6SXS jr7\r8\RX                  " S5      r9\7r:\6r; " S  S!5      r<\<" 5       r=SYS" jr> " S# S$5      r? " S% S&\?5      r@ " S' S(\?5      rA " S) S*5      rB " S+ S,5      rC " S- S.\C5      rD " S/ S0\C5      rE " S1 S25      rF " S3 S4\F5      rG " S5 S6\F5      rHSWSS7.S8 jjrI\R                  S9 5       rKS: rLS; rM\I" \R                  SZS< jS79 " S= S>\F5      5       rO\I" \R                  " \R                  S?S@95      " \F5      rRSA=\RlS        \RlT        SB\Rl         \I" \R                  S[SCSD.SE jjS79 " SF SG\F5      5       rV\I" \R                  S\SH jS79 " SI SJ\F5      5       rX " SK SL\F5      rY " SM SN\F5      rZ " SO SP\F5      r[SQ r\SR r]SS r^ " ST SU5      r_S]SV jr`gs  snn f s  snn f )^a  
A module for converting numbers or color arguments to *RGB* or *RGBA*.

*RGB* and *RGBA* are sequences of, respectively, 3 or 4 floats in the
range 0-1.

This module includes functions and classes for color specification conversions,
and for mapping numbers to colors in a 1-D array of colors called a colormap.

Mapping data onto colors using a colormap typically involves two steps: a data
array is first mapped onto the range 0-1 using a subclass of `Normalize`,
then this number is mapped to a color using a subclass of `Colormap`.  Two
subclasses of `Colormap` provided here:  `LinearSegmentedColormap`, which uses
piecewise-linear interpolation to define colormaps, and `ListedColormap`, which
makes a colormap from a list of colors.

.. seealso::

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

  :ref:`colormaps` for a list of built-in colormaps.

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

  More colormaps are available at palettable_.

The module also provides functions for checking whether an object can be
interpreted as a color (`is_color_like`), for converting such an object
to an RGBA tuple (`to_rgba`) or to an HTML-like hex string in the
"#rrggbb" format (`to_hex`), and a sequence of colors to an (n, 4)
RGBA array (`to_rgba_array`).  Caching is used for efficiency.

Colors that Matplotlib recognizes are listed at
:ref:`colors_def`.

.. _palettable: https://jiffyclub.github.io/palettable/
.. _xkcd color survey: https://xkcd.com/color/rgb/
    N)SizedSequenceMapping)Real)Image)PngInfo)_api_cmcbookscale_image   )BASE_COLORSTABLEAU_COLORSCSS4_COLORSXKCD_COLORSc                   @   ^  \ rS rSrU 4S jrU 4S jrU 4S jrSrU =r$ )_ColorMapping=   c                 2   > [         TU ]  U5        0 U l        g N)super__init__cache)selfmapping	__class__s     C/var/www/html/env/lib/python3.13/site-packages/matplotlib/colors.pyr   _ColorMapping.__init__>   s    !
    c                 X   > [         TU ]  X5        U R                  R                  5         g r   )r   __setitem__r   clear)r   keyvaluer   s      r   r"   _ColorMapping.__setitem__B   s     C'

r    c                 X   > [         TU ]  U5        U R                  R                  5         g r   )r   __delitem__r   r#   )r   r$   r   s     r   r(   _ColorMapping.__delitem__F   s     C 

r    )r   )	__name__
__module____qualname____firstlineno__r   r"   r(   __static_attributes____classcell__r   s   @r   r   r   =   s     r    r   greygray)i   @      c                      [         $ )z3Return the global mapping of names to named colors.)_colors_full_map r    r   get_named_colors_mappingr8   ]   s    r    c                   f   \ rS rSrSr\R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                   \R"                  \R$                  S.rS rS rS rS rS rS	 rS
 rSrg)ColorSequenceRegistryb   a  
Container for sequences of colors that are known to Matplotlib by name.

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

Read access uses a dict-like interface mapping names to lists of colors::

    import matplotlib as mpl
    colors = mpl.color_sequences['tab10']

For a list of built in color sequences, see :doc:`/gallery/color/color_sequences`.
The returned lists are copies, so that their modification does not change
the global definition of the color sequence.

Additional color sequences can be added via
`.ColorSequenceRegistry.register`::

    mpl.color_sequences.register('rgb', ['r', 'g', 'b'])
)tab10tab20tab20btab20cPastel1Pastel2PairedAccentDark2Set1Set2Set3	petroff10c                 *    0 U R                   EU l        g r   )_BUILTIN_COLOR_SEQUENCES_color_sequencesr   s    r   r   ColorSequenceRegistry.__init__   s     A4#@#@ Ar    c                 n     [        U R                  U   5      $ ! [         a    [        U< S35      ef = f)Nz# is not a known color sequence name)listrK   KeyErrorr   items     r   __getitem__!ColorSequenceRegistry.__getitem__   sB    	K--d344 	KdX%HIJJ	Ks    4c                 ,    [        U R                  5      $ r   )iterrK   rL   s    r   __iter__ColorSequenceRegistry.__iter__   s    D))**r    c                 ,    [        U R                  5      $ r   )lenrK   rL   s    r   __len__ColorSequenceRegistry.__len__   s    4(())r    c                 8    SSR                  S U  5       5      -   $ )Nz,ColorSequenceRegistry; available colormaps:
z, c              3   .   #    U  H  nS U S 3v   M     g7f)'Nr7   ).0names     r   	<genexpr>0ColorSequenceRegistry.__str__.<locals>.<genexpr>   s     7$$AdV1+$s   )joinrL   s    r   __str__ColorSequenceRegistry.__str__   s!    ?		7$778 	9r    c                     XR                   ;   a  [        U< S35      e[        U5      nU H  n [        U5        M     X R                  U'   g! [         a    [        U< S35      ef = f)a0  
Register a new color sequence.

The color sequence registry stores a copy of the given *color_list*, so
that future changes to the original list do not affect the registered
color sequence. Think of this as the registry taking a snapshot
of *color_list* at registration.

Parameters
----------
name : str
    The name for the color sequence.

color_list : list of :mpltype:`color`
    An iterable returning valid Matplotlib colors when iterating over.
    Note however that the returned color sequence will always be a
    list regardless of the input type.

z0 is a reserved name for a builtin color sequencez# is not a valid color specificationN)rJ   
ValueErrorrO   to_rgbarK   )r   ra   
color_listcolors       r   registerColorSequenceRegistry.register   s    ( 000x (. . / / *%
EE   '1d#	  E iBCE EEs   AA(c                 x    XR                   ;   a  [        SU< 35      eU R                  R                  US5        g)z
Remove a sequence from the registry.

You cannot remove built-in color sequences.

If the name is not registered, returns with no error.
z)Cannot unregister builtin color sequence N)rJ   rh   rK   popr   ra   s     r   
unregister ColorSequenceRegistry.unregister   s?     000;D8DF F!!$-r    )rK   N)r*   r+   r,   r-   __doc__r
   _tab10_data_tab20_data_tab20b_data_tab20c_data_Pastel1_data_Pastel2_data_Paired_data_Accent_data_Dark2_data
_Set1_data
_Set2_data
_Set3_data_petroff10_datarJ   r   rS   rW   r[   re   rl   rq   r.   r7   r    r   r:   r:   b   s    . """"$$$$""""((  BK+*9 1D.r    r:   c                 j    U c  U $  U R                  5       nU$ ! [         a    [        U 5      n U$ f = fr   )rR   AttributeErrorfloat)exrets     r   _sanitize_extremar      sB    	z	ggi J  BiJs    22z\AC[0-9]+\Zc                 Z    [        U [        5      =(       a    [        R                  U 5      $ )zDReturn whether *c* can be interpreted as an item in the color cycle.)
isinstancestr_nth_color_rematchcs    r   _is_nth_colorr      s    a8-"5"5a"88r    c                 j    [        U 5      (       a  g [        U 5        g! [        [        4 a     gf = f)z9Return whether *c* can be interpreted as an RGB(A) color.TF)r   ri   	TypeErrorrh   r   s    r   is_color_liker      s<     Q
  z" s    22c                 V    [        U [        5      (       + =(       a    [        U 5      S:H  $ )z4Return whether *c* is a color with an alpha channel.   )r   r   rZ   r   s    r   _has_alpha_channelr      s!     !S!!1c!fk1r    c                  z    U R                  5        H'  u  p[        U5      (       a  M  [        U< SU S35      e   g)zK
For each *key, value* pair in *kwargs*, check that *value* is color-like.
z is not a valid value for a*  : supported inputs are (r, g, b) and (r, g, b, a) 0-1 float tuples; '#rrggbb', '#rrggbbaa', '#rgb', '#rgba' strings; named color strings; string reprs of 0-1 floats for grayscale values; 'C0', 'C1', ... strings for colors of the color cycle; and pairs combining one of the above with an alpha valueN)itemsr   rh   )kwargskvs      r   _check_color_liker      sH     Q%1! 5K LM M r    c                    [        U 5      n [        U5      n[        U R                  S   S5      n[        UR                  S   S5      nX#:w  a  [        S5      eU R                  UR                  :H  =(       a    X:H  R	                  5       $ )zs
Return whether the colors *c1* and *c2* are the same.

*c1*, *c2* can be single colors or lists/arrays of colors.
r   r   z$Different number of elements passed.)to_rgba_arraymaxshaperh   all)c1c2n1n2s       r   
same_colorr     st     
r	B	r	B	RXXa[!	B	RXXa[!	B	x?@@ 88rxx4RXNN$44r    c                    [        U [        5      (       a  [        U 5      S:X  a  Uc  U u  pOU S   n [        U 5      (       aQ  [        R
                  S   nUR                  5       R                  SS/5      nU[        U SS 5      [        U5      -     n  [        R                  X4   nUc"  [        X5      n U[        R                  X4'   U$ U$ ! [        [        4 a    Sn N;f = f! [         a     U$ f = f)aN  
Convert *c* to an RGBA color.

Parameters
----------
c : Matplotlib color or ``np.ma.masked``

alpha : float, optional
    If *alpha* is given, force the alpha value of the returned RGBA tuple
    to *alpha*.

    If None, the alpha value from *c* is used. If *c* does not have an
    alpha channel, then alpha defaults to 1.

    *alpha* is ignored for the color value ``"none"`` (case-insensitive),
    which always maps to ``(0, 0, 0, 0)``.

Returns
-------
tuple
    Tuple of floats ``(r, g, b, a)``, where each channel (red, green, blue,
    alpha) can assume values between 0 and 1.
   Nr   zaxes.prop_cyclerk   r   r   )r   tuplerZ   r   mplrcParamsby_keygetintr6   r   rP   r   _to_rgba_no_colorcycle)r   alphaprop_cyclercolorsrgbas        r   ri   ri     s   0 !UA!=HAu!AQll#45##%))'C593qu:F+,%%ah/ |%a/	/3""18, K4K i    	K	s$   C 7C' C$#C$'
C54C5c                 `   Ub  SUs=::  a  S::  d  O  [        S5      eU nU [        R                  R                  L a  g[	        U [
        5      (       a  U R                  5       S:X  a  g [        U    n [	        U [
        5      (       Ga  [        R                  " SU 5      nU(       a*  [        S U SS	 U S	S
 U S
S 4 5       5      Ub  U4-   $ S4-   $ [        R                  " SU 5      nU(       a3  [        S U S   S-  U S   S-  U S	   S-  4 5       5      Ub  U4-   $ S4-   $ [        R                  " SU 5      nU(       aA  U SS	 U S	S
 U S
S U SS 4 Vs/ s H  n[        US5      S-  PM     nnUb  XS'   [        U5      $ [        R                  " SU 5      nU(       aM  U S   S-  U S   S-  U S	   S-  U S   S-  4 Vs/ s H  n[        US5      S-  PM     nnUb  XS'   [        U5      $  [        U 5      n SU s=::  a  S::  d  O  [        SU< S35      eX Xb  U4$ S4$ [	        U [        R                  5      (       a4  U R                   S:X  a$  U R"                  S   S:X  a  U R%                  S5      n [        R&                  " U 5      (       d  [        SU< 35      e[        U 5      S;  a  [        S5      e[)        S U  5       5      (       d  [        SU< 35      e[        [+        [        U 5      5      n [        U 5      S	:X  a  Uc  SnUb	  U SS	 U4-   n [-        S U  5       5      (       a  [        S5      eU $ ! [         a@    [        U5      S:w  a-   [        U R                  5          n  GN! [         a      GN
f = f GNf = fs  snf s  snf ! [          a     Of = f[        SU< 35      e)ad  
Convert *c* to an RGBA color, with no support for color-cycle syntax.

If *alpha* is given, force the alpha value of the returned RGBA tuple
to *alpha*. Otherwise, the alpha value from *c* is used, if it has alpha
information, or defaults to 1.

*alpha* is ignored for the color value ``"none"`` (case-insensitive),
which always maps to ``(0, 0, 0, 0)``.
Nr   r   *'alpha' must be between 0 and 1, inclusive        r   r   r   none\A#[a-fA-F0-9]{6}\Zc              3   @   #    U  H  n[        US 5      S-  v   M     g7f      Nr   r`   ns     r   rb   )_to_rgba_no_colorcycle.<locals>.<genexpr>f  "      =#;a a*s*#;                  ?z\A#[a-fA-F0-9]{3}\Zc              3   @   #    U  H  n[        US 5      S-  v   M     g7fr   r   r   s     r   rb   r   l  r   r   r   z\A#[a-fA-F0-9]{8}\Z	   r   r   z\A#[a-fA-F0-9]{4}\Zr   zInvalid string grayscale value z . Value must be within 0-1 rangezInvalid RGBA argument: r   r   z'RGBA sequence should have length 3 or 4c              3   B   #    U  H  n[        U[        5      v   M     g 7fr   )r   r   )r`   xs     r   rb   r     s     .Aqz!T""A   c              3   B   #    U  H  oS :  =(       d    US:  v   M     g7f)r   r   Nr7   )r`   elems     r   rb   r     s     
.AD!8taxAr   &RGBA values should be within 0-1 range)rh   npmamaskedr   r   lowerr6   rP   rZ   rer   r   r   r   ndarrayndimr   reshapeiterabler   mapany)r   r   orig_cr   r   rk   s         r   r   r   E  s    eqEFFFBEELL!S779#	 #A !S/3 =$%aFAaFAaF#;= = % 1u;< =79;< = /3 =$%aDFAaDFAaDF#;= = % 1u;< =79;< = /3 1vq1vq1vq1v>@> BZ#%>  @ !b	</3 tAvqtAvqtAvqtAv>@> BZ#%>  @ !b	<		?aA KaK 5fZ @5 67 7 %6E>>B>> !RZZ  66Q;1771:?		"A;;q>>26*=>>
1vVBCC.A... 26*=>>c%mA
1v{u}bqEUH

.A
...ABBHI  	6{a(3A   	,@@  		 26*=>>sN   )	L: N>N,N :NM..
M=8N<M==NN
NNc           	      
   [        U [        5      (       a4  [        U 5      S:X  a%  [        U S   [        5      (       a  Uc  U u  pOU S   n [        R
                  " U5      (       a$  [        R                  " U5      R                  5       n[        U [        R                  5      (       Ga  U R                  R                  S;   Ga  U R                  S:X  Ga  U R                  S   S;   Ga  [        R                  R                  U 5      (       a  U R                  R!                  SS9OSn[        R                  R#                  U 5      n [        R
                  " U5      (       aw  U R                  S   S:X  a9  UR                  S   S:  a&  [        R$                  " XR                  S   S45      n O+U R                  S   UR                  S   :w  a  ['        S5      eU R                  S   S	:X  aD  [        R(                  " U [        R*                  " [        U 5      5      /5      nUb  UOS
USS2S4'   O.U R                  S   S:X  a  U R-                  5       nUb  XSS2S4'   Ub  SWU'   [        R                   " WS:  US:  -  5      (       a  ['        S5      eU$ [.        R0                  " U S5      (       a  [        R*                  " S[2        5      $  [        R
                  " U5      (       a5  [        R4                  " U Vs/ s H  n[7        X5      PM     sn[2        5      $ [        R4                  " [7        X5      /[2        5      $ s  snf ! [8         a     O([&         a  nUR:                  S:X  a  Ue SnAOSnAff = f[        U [<        5      (       a  ['        U < S35      e[        U 5      S:X  a  [        R*                  " S[2        5      $ [        U [>        5      (       a  U  Vs1 s H+  n[        U[@        [        45      (       a  [        U5      OSiM-     Os  snf nnUS	1:X  a6  [        R(                  " U [        RB                  " [        U 5      5      /5      nOUS1:X  a  [        R4                  " U 5      nOm[        R4                  " U  Vs/ s H  n[7        U5      PM     Os  snf sn5      nO6[        R4                  " U  Vs/ s H  n[7        U5      PM     Os  snf sn5      nUbV  XSS2S	4'   [        U [>        5      (       a9  U  Vs/ s H  n[.        RD                  " US5      PM     Os  snf n	nSUSS2S	4   U	'   U$ )a`  
Convert *c* to a (n, 4) array of RGBA colors.

Parameters
----------
c : Matplotlib color or array of colors
    If *c* is a masked array, an `~numpy.ndarray` is returned with a
    (0, 0, 0, 0) row for each masked value or row in *c*.

alpha : float or sequence of floats, optional
    If *alpha* is given, force the alpha value of the returned RGBA tuple
    to *alpha*.

    If None, the alpha value from *c* is used. If *c* does not have an
    alpha channel, then alpha defaults to 1.

    *alpha* is ignored for the color value ``"none"`` (case-insensitive),
    which always maps to ``(0, 0, 0, 0)``.

    If *alpha* is a sequence and *c* is a single color, *c* will be
    repeated to match the length of *alpha*.

Returns
-------
array
    (n, 4) array of RGBA colors,  where each channel (red, green, blue,
    alpha) can assume values between 0 and 1.
r   r   Nr   ifr   axisz^The number of colors must match the number of alpha values if there are more than one of each.r   r   r   r   r   r   )r   r   )r   z is not a valid color value.)#r   r   rZ   r   r   r   asarrayravelr   dtypekindr   r   r   	is_maskedmaskr   getdatatilerh   column_stackzeroscopyr   _str_lower_equalr   arrayri   r   argsr   r   rO   ones
_str_equal)
r   r   r   resultaecclensr   	none_masks
             r   r   r     s   : !UA!
1Q40F0F=HAu!A 
{{5

5!'')1bjj!!agglld&:!
f 4%'UU__Q%7%7qvvzzqz!TEEMM!;;uwwqzQ5;;q>A#5GGAA23u{{1~-  "- . . 771:?__a#a&)9%:;F%*%6EBF1b5MWWQZ1_VVXF  %q"uF4L666A:&1*-..EFF
 a((xx&&
;;u88E:EqWQ]E:EBB88WQ./77 ;   66EEG F !SA5 <=>>
1v{xx&& !XKLM1R:b4-88Bb@1MMA3;??Arwws1v#78DaS[88A;D88151RWR[156Dxxq1qq12QT
a"" ABB"))"f5BIB$%DAJy!KsN   /M	 >MM	 $M	 M	 	
M:	M:M55M:$2PR#S
!T,c                     [        U 5      SS $ )zAConvert *c* to an RGB color, silently dropping the alpha channel.Nr   )ri   r   s    r   to_rgbr     s    1:bq>r    c                 f    [        U 5      n U(       d  U SS n SSR                  S U  5       5      -   $ )a  
Convert *c* to a hex color.

Parameters
----------
c : :ref:`color <colors_def>` or `numpy.ma.masked`

keep_alpha : bool, default: False
  If False, use the ``#rrggbb`` format, otherwise use ``#rrggbbaa``.

Returns
-------
str
  ``#rrggbb`` or ``#rrggbbaa`` hex color string
Nr   # c              3   R   #    U  H  n[        [        US -  5      S5      v   M     g7f)r   02xN)formatround)r`   vals     r   rb   to_hex.<locals>.<genexpr>'  s#     FAScCi 0%88As   %')ri   rd   )r   
keep_alphas     r   to_hexr    s5      	
AbqEFAFFFFr    r   c                   d    \ rS rSrSr\r\R                  r\" \	5      r	\" \
5      r
\" \5      rSrg)ColorConverteri3  zs
A class only kept for backwards compatibility.

Its functionality is entirely provided by module-level functions.
r7   N)r*   r+   r,   r-   rs   r6   r   r   staticmethodr   ri   r   r.   r7   r    r   r  r  3  s7    
 F""E&!F7#G /Mr    r  c                    [        U5      (       aR  [        R                  " SSU 5      U-  n[        R                  " [        R                  " U" U5      [
        S9SS5      nU$  [        R                  " U5      n[        R                  " SUS9  USS2S4   nUSS2S4   nUSS2S4   n	US   S	:w  d	  US
   S:w  a  [        S5      e[        R                  " U5      S:  R                  5       (       a  [        S5      eU S:X  a  [        R                  " US
   5      nOXpS-
  -  nU S-
  [        R                  " SSU 5      U-  -  n[        R                  " Xs5      SS
 n
USS
 XzS-
     -
  Xz   XzS-
     -
  -  n[        R                  " U	S   /XU
   XS-
     -
  -  XS-
     -   US
   //5      n[        R                  " US	S5      $ ! [         a  n[        S5      UeSnAff = f)a  
Create an *N* -element 1D lookup table.

This assumes a mapping :math:`f : [0, 1] \rightarrow [0, 1]`. The returned
data is an array of N values :math:`y = f(x)` where x is sampled from
[0, 1].

By default (*gamma* = 1) x is equidistantly sampled from [0, 1]. The
*gamma* correction factor :math:`\gamma` distorts this equidistant
sampling by :math:`x \rightarrow x^\gamma`.

Parameters
----------
N : int
    The number of elements of the created lookup table; at least 1.

data : (M, 3) array-like or callable
    Defines the mapping :math:`f`.

    If a (M, 3) array-like, the rows define values (x, y0, y1).  The x
    values must start with x=0, end with x=1, and all x values be in
    increasing order.

    A value between :math:`x_i` and :math:`x_{i+1}` is mapped to the range
    :math:`y^1_{i-1} \ldots y^0_i` by linear interpolation.

    For the simple case of a y-continuous mapping, y0 and y1 are identical.

    The two values of y are to allow for discontinuous mapping functions.
    E.g. a sawtooth with a period of 0.2 and an amplitude of 1 would be::

        [(0, 1, 0), (0.2, 1, 0), (0.4, 1, 0), ..., [(1, 1, 0)]

    In the special case of ``N == 1``, by convention the returned value
    is y0 for x == 1.

    If *data* is a callable, it must accept and return numpy arrays::

       data(x : ndarray) -> ndarray

    and map values between 0 - 1 to 0 - 1.

gamma : float
    Gamma correction factor for input distribution x of the mapping.

    See also https://en.wikipedia.org/wiki/Gamma_correction.

Returns
-------
array
    The lookup table where ``lut[x * (N-1)]`` gives the closest value
    for values of x between 0 and 1.

Notes
-----
This function is internally used for `.LinearSegmentedColormap`.
r   r   r   z$data must be convertible to an arrayN)Nr   )datar   r   r   r   z8data mapping points must start with x=0 and end with x=1z3data mapping points must have x in increasing order)callabler   linspaceclipr   r   	Exceptionr   r	   check_shaperh   diffr   searchsortedconcatenate)Nr  gammaxindlutadataerrr   y0y1inddistances               r   _create_lookup_tabler  F  s   v ~~{{1a#u,ggbhhtDz7A>
I 	YU+adA	q!tB	q!tBtrzQrUc\FH 	H

QNOOAvhhr"vQKAQ1-66ooa&q,2J7+70CDnnUG3"1W+-.!G<VH
  773S!!;  I>?SHIs   $G 
G"GG"c                       \ rS rSrSrSS jrSS jrSS jrS rS r	S	 r
SS
 jrS rSS jrS rSS jrSSSS.S jrSSSS.S jrS rS rS rS rSS jrS rS rS rSrg)Colormapi  a  
Baseclass for all scalar to RGBA mappings.

Typically, Colormap instances are used to convert data values (floats)
from the interval ``[0, 1]`` to the RGBA color that the respective
Colormap represents. For scaling of data into the ``[0, 1]`` interval see
`matplotlib.colors.Normalize`. Subclasses of `matplotlib.cm.ScalarMappable`
make heavy use of this ``data -> normalize -> map-to-color`` processing
chain.
c                     Xl         [        U5      U l        SU l        SU l        SU l        U R                  U l        U R                  S-   U l        U R                  S-   U l        SU l	        SU l
        SU l        g)zs
Parameters
----------
name : str
    The name of the colormap.
N : int
    The number of RGB quantization levels.
r   Nr   r   F)ra   r   r  	_rgba_bad_rgba_under
_rgba_over_i_under_i_over_i_bad_isinit
n_variatescolorbar_extend)r   ra   r  s      r   r   Colormap.__init__  sk     	Q-vvzffqj
  %r    Nc                 v    U R                  XUS9u  pE[        R                  " U5      (       d  [        U5      nU$ )aB  
Parameters
----------
X : float or int or array-like
    The data value(s) to convert to RGBA.
    For floats, *X* should be in the interval ``[0.0, 1.0]`` to
    return the RGBA values ``X*100`` percent along the Colormap line.
    For integers, *X* should be in the interval ``[0, Colormap.N)`` to
    return RGBA values *indexed* from the Colormap with index ``X``.
alpha : float or array-like or None
    Alpha must be a scalar between 0 and 1, a sequence of such
    floats with shape matching X, or None.
bytes : bool, default: False
    If False (default), the returned RGBA values will be floats in the
    interval ``[0, 1]`` otherwise they will be `numpy.uint8`\s in the
    interval ``[0, 255]``.

Returns
-------
Tuple of RGBA values if X is scalar, otherwise an array of
RGBA values with a shape of ``X.shape + (4, )``.
)r   bytes)_get_rgba_and_maskr   r   r   )r   Xr   r*  r   r   s         r   __call__Colormap.__call__  s6    . ,,Q5,I
{{1~~;Dr    c                    U R                   (       d  U R                  5         [        R                  " USS9nUR                  R
                  (       d7  UR                  5       R                  UR                  R                  5       5      nUR                  R                  S:X  a,  X@R                  -  nU R                  S-
  XDU R                  :H  '   US:  nX@R                  :  n[        R                  R                  U5      (       a  UR                  O[        R                  " U5      n[        R                  " SS9   UR!                  ["        5      nSSS5        U R$                  XE'   U R&                  XF'   U R(                  XG'   U R*                  nU(       a"  US	-  R!                  [        R,                  5      nUR/                  USS
S9n	Ub  [        R0                  " USS5      nU(       a  US	-  nUR2                  SUR2                  4;  a%  [5        SUR2                   SUR2                   35      eX)S'   US   S:H  R7                  5       (       a  SX'   X4$ ! , (       d  f       GN= f)a  
Parameters
----------
X : float or int or array-like
    The data value(s) to convert to RGBA.
    For floats, *X* should be in the interval ``[0.0, 1.0]`` to
    return the RGBA values ``X*100`` percent along the Colormap line.
    For integers, *X* should be in the interval ``[0, Colormap.N)`` to
    return RGBA values *indexed* from the Colormap with index ``X``.
alpha : float or array-like or None
    Alpha must be a scalar between 0 and 1, a sequence of such
    floats with shape matching X, or None.
bytes : bool, default: False
    If False (default), the returned RGBA values will be floats in the
    interval ``[0, 1]`` otherwise they will be `numpy.uint8`\s in the
    interval ``[0, 255]``.

Returns
-------
colors : np.ndarray
    Array of RGBA values with a shape of ``X.shape + (4, )``.
mask : np.ndarray
    Boolean array with True where the input is ``np.nan`` or masked.
Tr   fr   r   ignoreinvalidNr   r  )r   moder7   "alpha is array-like but its shape z does not match that of X .r   r   r   r   r   r   )r%  _initr   r   r   isnativebyteswapviewnewbyteorderr   r  r   r   r   isnanerrstateastyper   r"  r#  r$  _lutuint8taker  r   rh   r   )
r   r,  r   r*  xa
mask_under	mask_overmask_badr  r   s
             r   r+  Colormap._get_rgba_and_mask  s   2 ||JJLXXad#xx  ##BHH$9$9$;<B88==C&&LB#vvzBTVV| !V
&&L	UU__Q//166RXXb\[[*3B + {{ii9$$RXX.Cxxx0GGE1a(E{{2rxx.0 8 F++-88*67 7 "MB1!!##!-~5 +*s   <I
I'c                     U R                   nUR                  U5      nUR                  R                  U R                  5        U R                  (       a%  [
        R                  " U R                  5      Ul        U$ r   )r   __new____dict__updater%  r   r   rA  r   cls
cmapobjects      r   __copy__Colormap.__copy__/  sR    nn[[%
""4==1<< ggdii0JOr    c                 <   [        U[        5      (       a  U R                  UR                  :w  a  gU R                  (       d  U R	                  5         UR                  (       d  UR	                  5         [
        R                  " U R                  UR                  5      $ NF)r   r  r'  r%  r9  r   array_equalrA  r   others     r   __eq__Colormap.__eq__7  s_    5(++$$(=(==||JJL}}KKM~~dii44r    c                     U R                   (       d  U R                  5         [        R                  " U R                  U R
                     5      $ z Get the color for masked values.)r%  r9  r   r   rA  r$  rL   s    r   get_badColormap.get_badB  s.    ||JJLxx		$++.//r    c                 h    [        X5      U l        U R                  (       a  U R                  5         gg)z Set the color for masked values.N)ri   r  r%  _set_extremesr   rk   r   s      r   set_badColormap.set_badH  s&     .<<  r    c                     U R                   (       d  U R                  5         [        R                  " U R                  U R
                     5      $ )z*Get the color for low out-of-range values.)r%  r9  r   r   rA  r"  rL   s    r   	get_underColormap.get_underN  s.    ||JJLxx		$--011r    c                 h    [        X5      U l        U R                  (       a  U R                  5         gg)z*Set the color for low out-of-range values.N)ri   r   r%  r^  r_  s      r   	set_underColormap.set_underT  s'    "50<<  r    c                     U R                   (       d  U R                  5         [        R                  " U R                  U R
                     5      $ )z+Get the color for high out-of-range values.)r%  r9  r   r   rA  r#  rL   s    r   get_overColormap.get_overZ  s.    ||JJLxx		$,,/00r    c                 h    [        X5      U l        U R                  (       a  U R                  5         gg)z+Set the color for high out-of-range values.N)ri   r!  r%  r^  r_  s      r   set_overColormap.set_over`  s&    !%/<<  r    badunderoverc                ~    Ub  U R                  U5        Ub  U R                  U5        Ub  U R                  U5        gg)z
Set the colors for masked (*bad*) values and, when ``norm.clip =
False``, low (*under*) and high (*over*) out-of-range values.
N)r`  rf  rl  )r   ro  rp  rq  s       r   set_extremesColormap.set_extremesf  s>    
 ?LLNN5!MM$ r    c                F    U R                  5       nUR                  XUS9  U$ )z
Return a copy of the colormap, for which the colors for masked (*bad*)
values and, when ``norm.clip = False``, low (*under*) and high (*over*)
out-of-range values, have been set accordingly.
rn  )r   rs  )r   ro  rp  rq  new_cms        r   with_extremesColormap.with_extremesr  s'     t<r    c                    U R                   (       a$  U R                   U R                  U R                  '   O&U R                  S   U R                  U R                  '   U R                  (       a$  U R                  U R                  U R                  '   O3U R                  U R
                  S-
     U R                  U R                  '   U R                  U R                  U R                  '   g )Nr   r   )r   rA  r"  r!  r#  r  r  r$  rL   s    r   r^  Colormap._set_extremes|  s    '+'7'7DIIdmm$'+yy|DIIdmm$??&*ooDIIdll#&*ii
&;DIIdll#!%		$++r    c                     [        S5      ez)Generate the lookup table, ``self._lut``.zAbstract class onlyNotImplementedErrorrL   s    r   r9  Colormap._init      !"788r    c                 >   U R                   (       d  U R                  5         [        R                  " U R                  SS2S4   U R                  SS2S4   :H  5      =(       a;    [        R                  " U R                  SS2S4   U R                  SS2S4   :H  5      $ )z)Return whether the colormap is grayscale.Nr   r   r   )r%  r9  r   r   rA  rL   s    r   is_grayColormap.is_gray  sn    ||JJLtyyA$))AqD/9: ;tyyA$))AqD/9:	<r    c                     [        U S5      (       a4  [        R                  " S[        U 5       S35        U R	                  U5      $ [        5       e)-Return a new colormap with *lutsize* entries.	_resamplezHThe ability to resample a color map is now public API However the class zX still only implements the previous private _resample method.  Please update your class.)hasattrr	   warn_externaltyper  r~  )r   lutsizes     r   	resampledColormap.resampled  sO    4%%%%)$ZL 1 >>'**!##r    c                     [        5       e)aC  
Return a reversed instance of the Colormap.

.. note:: This function is not implemented for the base class.

Parameters
----------
name : str, optional
    The name for the reversed colormap. If None, the
    name is set to ``self.name + "_r"``.

See Also
--------
LinearSegmentedColormap.reversed
ListedColormap.reversed
r}  rp   s     r   reversedColormap.reversed  s    " "##r    c                    [         R                  " [         R                  " SS[        S   5      [        S   S45      nU " USS9n[        R
                  " 5       nU R                  S-   nS[        R                   S3n[        5       nUR                  SU5        UR                  S	U5        UR                  S
U5        UR                  SU5        [        R                  " U5      R                  USUS9  UR                  5       $ ).Generate a PNG representation of the Colormap.r   r   Tr*  z	 colormapMatplotlib v, https://matplotlib.orgTitleDescriptionAuthorSoftwarepngr   pnginfo)r   r   r
  _REPR_PNG_SIZEioBytesIOra   r   __version__r   add_textr   	fromarraysavegetvalue)r   r,  pixels	png_bytestitleauthorr  s          r   
_repr_png_Colormap._repr_png_  s    GGBKK1nQ&78#A&*,at$JJL			K'00HI)%(.6*V,$$Yug$N!!##r    c                 p   U R                  5       n[        R                  " U5      R                  S5      nS nSU R                   SU R                   SU R                   SU S[
        S   S	-    S
U" U R                  5       5       SU" U R                  5       5       SU" U R                  5       5       S3$ )0Generate an HTML representation of the Colormap.asciic                 (    [        U SS9nSU SU S3$ NT)r  z<div title="z" style="display: inline-block; width: 1em; height: 1em; margin: 0; vertical-align: middle; border: 1px solid #555; background-color: z	;"></div>r  rk   	hex_colors     r   color_block)Colormap._repr_html_.<locals>.color_block  -    u6I"9+ .) *39> ?r    -<div style="vertical-align: middle;"><strong>,</strong> </div><div class="cmap"><img alt="z colormap" title="=" style="border: 1px solid #555;" src="data:image/png;base64,7"></div><div style="vertical-align: middle; max-width: r   r   Npx; display: flex; justify-content: space-between;"><div style="float: left;">zD under</div><div style="margin: 0 auto; display: inline-block;">bad z&</div><div style="float: right;">over </div></div>)	r  base64	b64encodedecodera   r  rc  r[  ri  r   r  
png_base64r  s       r   _repr_html_Colormap._repr_html_  s    OO%	%%i077@
	?99+ & 		{ #)) %..8\ :,Q/12 3- t~~/01 2 #4<<>23#DMMO45' 	r    c                 "    U R                  5       $ zReturn a copy of the colormap.rP  rL   s    r   r   Colormap.copy      }}r    )r  r$  r#  r"  r%  r  r!  r   r'  r&  ra   )r4   rS  )r   Nr   )r*   r+   r,   r-   rs   r   r-  r+  rP  rW  r[  r`  rc  rf  ri  rl  rs  rw  r^  r9  r  r  r  r  r  r   r.   r7   r    r   r  r    s    	%28DL	50!2!1! #'d 
  $(t$ 	09<$$&$ "Hr    r  c                   p   ^  \ rS rSrSrSU 4S jjrS rS r\SS j5       r	S r
\S 5       rSS	 jrS
rU =r$ )LinearSegmentedColormapi  z
Colormap objects based on lookup tables using linear segments.

The lookup table is generated using linear interpolation for each
primary color, with the 0-1 domain divided into any number of
segments.
c                 J   > SU l         [        TU ]	  X5        X l        X@l        g)a  
Create colormap from linear mapping segments

segmentdata argument is a dictionary with a red, green and blue
entries. Each entry should be a list of *x*, *y0*, *y1* tuples,
forming rows in a table. Entries for alpha are optional.

Example: suppose you want red to increase from 0 to 1 over
the bottom half, green to do the same over the middle half,
and blue over the top half.  Then you would use::

    cdict = {'red':   [(0.0,  0.0, 0.0),
                       (0.5,  1.0, 1.0),
                       (1.0,  1.0, 1.0)],

             'green': [(0.0,  0.0, 0.0),
                       (0.25, 0.0, 0.0),
                       (0.75, 1.0, 1.0),
                       (1.0,  1.0, 1.0)],

             'blue':  [(0.0,  0.0, 0.0),
                       (0.5,  0.0, 0.0),
                       (1.0,  1.0, 1.0)]}

Each row in the table for a given color is a sequence of
*x*, *y0*, *y1* tuples.  In each sequence, *x* must increase
monotonically from 0 to 1.  For any input value *z* falling
between *x[i]* and *x[i+1]*, the output value of a given color
will be linearly interpolated between *y1[i]* and *y0[i+1]*::

    row i:   x  y0  y1
                   /
                  /
    row i+1: x  y0  y1

Hence y0 in the first row and y1 in the last row are never used.

See Also
--------
LinearSegmentedColormap.from_list
    Static method; factory function for generating a smoothly-varying
    LinearSegmentedColormap.
FN)
monochromer   r   _segmentdata_gamma)r   ra   segmentdatar  r  r   s        r   r    LinearSegmentedColormap.__init__  s%    Z  !'r    c                    [         R                  " U R                  S-   S4[        5      U l        [        U R                  U R                  S   U R                  5      U R                  S S2S4'   [        U R                  U R                  S   U R                  5      U R                  S S2S4'   [        U R                  U R                  S   U R                  5      U R                  S S2S	4'   S
U R                  ;   a5  [        U R                  U R                  S
   S5      U R                  S S2S4'   SU l        U R                  5         g )Nr   r   redr   greenr   bluer   r   T)
r   r   r  r   rA  r  r  r  r%  r^  rL   s    r   r9  LinearSegmentedColormap._init&  s   GGTVVaZOU3	0FFD%%e,dkk;		#2#q&0FFD%%g.=		#2#q&0FFD%%f-t{{<		#2#q&d''' 4))'2A!7DIIcrc1fr    c                 0    Xl         U R                  5         g)z.Set a new gamma value and regenerate colormap.N)r  r9  )r   r  s     r   	set_gamma!LinearSegmentedColormap.set_gamma4  s    

r    c                 0   [         R                  " U5      (       d  [        S5      e[        US   [        5      (       a5  [        US   5      S:X  a#  [        US   [        5      (       d  [        U6 u  pAO![         R                  " SS[        U5      5      n[        U5      R                  u  pVpx[         R                  " XEU/5      [         R                  " XFU/5      [         R                  " XGU/5      [         R                  " XHU/5      S.n	[        X	X#5      $ )a  
Create a `LinearSegmentedColormap` from a list of colors.

Parameters
----------
name : str
    The name of the colormap.
colors : list of :mpltype:`color` or list of (value, color)
    If only colors are given, they are equidistantly mapped from the
    range :math:`[0, 1]`; i.e. 0 maps to ``colors[0]`` and 1 maps to
    ``colors[-1]``.
    If (value, color) pairs are given, the mapping is from *value*
    to *color*. This can be used to divide the range unevenly.
N : int
    The number of RGB quantization levels.
gamma : float
zcolors must be iterabler   r   r   )r  r  r  r   )r   r   rh   r   r   rZ   r   zipr
  r   Tr   r  )
ra   r   r  r  valsrgbr   cdicts
             r   	from_list!LinearSegmentedColormap.from_list9  s    & {{6""677vay%((S^q-@"6!9c22<LD&;;q!S[1D"6*,,
a??DQ<0__dq\2OOTaL1__dq\2	
 'tA==r    c                     [        U R                  U R                  U5      nU R                  Ul        U R                  Ul        U R
                  Ul        U$ )r  )r  ra   r  r!  r   r  )r   r  new_cmaps      r   r  !LinearSegmentedColormap.resampled`  sH    *499d6G6G+24"oo#//!^^r    c                     U " SU-
  5      $ )Nr   r7   )funcr   s     r   	_reverser!LinearSegmentedColormap._reverserj  s    AE{r    c                 
   Uc  U R                   S-   nU R                  R                  5        VVVVVs0 s H_  u  p#U[        U5      (       a!  [        R
                  " U R                  U5      O'[        U5       VVVs/ s H  u  pEnSU-
  Xe4PM     snnn_Ma     nnnnnn[        XU R                  U R                  5      nU R                  Ul        U R                  Ul        U R                  Ul        U$ s  snnnf s  snnnnnf )z
Return a reversed instance of the Colormap.

Parameters
----------
name : str, optional
    The name for the reversed colormap. If None, the
    name is set to ``self.name + "_r"``.

Returns
-------
LinearSegmentedColormap
    The reversed colormap.
_rr   )ra   r  r   r	  	functoolspartialr  r  r  r  r  r   r!  r  )	r   ra   r$   r  r   r  r  data_rr  s	            r   r   LinearSegmentedColormap.reversedn  s     <99t#D $(#4#4#:#:#<> $=ic #D>> "))$..$?<DTNKNyqb#'2*NKL $= 	 >
 +4M"..#!^^ L>s   A	C<<C5	C<5C<)r  r%  rA  r  r  )r4   r   r   )r*   r+   r,   r-   rs   r   r9  r  r  r  r  r  r  r.   r/   r0   s   @r   r  r    sP    0d
 $> $>L   r    r  c                   F   ^  \ rS rSrSrSU 4S jjrS rS rS	S jrSr	U =r
$ )
ListedColormapi  a  
Colormap object generated from a list of colors.

This may be most useful when indexing directly into a colormap,
but it can also be used to generate special colormaps for ordinary
mapping.

Parameters
----------
colors : list, array
    Sequence of Matplotlib color specifications (color names or RGB(A)
    values).
name : str, optional
    String to identify the colormap.
N : int, optional
    Number of entries in the map. The default is *None*, in which case
    there is one colormap entry for each element in the list of colors.
    If ::

        N < len(colors)

    the list will be truncated at *N*. If ::

        N > len(colors)

    the list will be extended by repetition.
c                   > SU l         Uc  Xl        [        U5      nO[        U[        5      (       a  U/U-  U l        SU l         O[
        R                  " U5      (       aP  [        U5      S:X  a  SU l         [        [        R                  " [        R                  " U5      U5      5      U l        O [        U5      nU/U-  U l        SU l         [        TU ]9  X#5        g ! [         a     N#f = f)NFTr   )r  r   rZ   r   r   r   r   rO   	itertoolsislicecycler   r   r   r   )r   r   ra   r  r2   r   s        r   r   ListedColormap.__init__  s    9 KFA&#&&%hl"&V$$v;!#&*DO"$$Y__V%<a@B- =D $(&1*DK"&! ! s   2C 
C,+C,c                     [         R                  " U R                  S-   S4[        5      U l        [        U R                  5      U R                  S S& SU l        U R                  5         g )Nr   r   r  T)	r   r   r  r   rA  r   r   r%  r^  rL   s    r   r9  ListedColormap._init  sK    HHdffqj!_e4	&t{{3		#2r    c                     U " [         R                  " SSU5      5      n[        X R                  S9nU R                  Ul        U R
                  Ul        U R                  Ul        U$ )r  r   r   ra   )r   r
  r  ra   r!  r   r  )r   r  r   r  s       r   r  ListedColormap.resampled  sR    bkk!Q01!&yy9"oo#//!^^r    c                     Uc  U R                   S-   n[        [        U R                  5      5      n[	        X!U R
                  S9nU R                  Ul        U R                  Ul        U R                  Ul        U$ )a   
Return a reversed instance of the Colormap.

Parameters
----------
name : str, optional
    The name for the reversed colormap. If None, the
    name is set to ``self.name + "_r"``.

Returns
-------
ListedColormap
    A reversed instance of the colormap.
r  ra   r  )	ra   rO   r  r   r  r  r   r!  r  )r   ra   colors_rr  s       r   r  ListedColormap.reversed  se     <99t#D-.!(@"..#!^^r    )r%  rA  r   r  )r  Nr   )r*   r+   r,   r-   rs   r   r9  r  r  r.   r/   r0   s   @r   r  r    s!    6"0 r    r  c                       \ rS rSrSrSS jrSS jrS rS rS r	S	 r
S
 rS rS rS rS rSSSS.S jr\S 5       rS rS rSrg)MultivarColormapi  zn
Class for holding multiple `~matplotlib.colors.Colormap` for use in a
`~matplotlib.cm.ScalarMappable` object
c                    X0l         [        R                  " U5      (       a$  [        U5      S:X  d  [	        U[
        5      (       a  [        S5      e[        U5      n[        U5       HQ  u  pE[	        U[
        5      (       a  [        R                  U   X'   M1  [	        U[        5      (       a  MH  [        S5      e   Xl        [        R                  " SS/US9  X l        [        U5      U l        SU l        g)	a  
Parameters
----------
colormaps: list or tuple of `~matplotlib.colors.Colormap` objects
    The individual colormaps that are combined
combination_mode: str, 'sRGB_add' or 'sRGB_sub'
    Describe how colormaps are combined in sRGB space

    - If 'sRGB_add' -> Mixing produces brighter colors
      `sRGB = sum(colors)`
    - If 'sRGB_sub' -> Mixing produces darker colors
      `sRGB = 1 - sum(1 - colors)`
name : str, optional
    The name of the colormap family.
r   z4A MultivarColormap must have more than one colormap.zdcolormaps must be a list of objects that subclass Colormap or a name found in the colormap registry.sRGB_addsRGB_sub)combination_moder   N)ra   r   r   rZ   r   r   rh   rO   	enumerater   	colormapsr  
_colormapsr	   check_in_list_combination_moder&  r  )r   r  r  ra   icmaps         r   r   MultivarColormap.__init__  s      	{{9%%)n!C((STTO	 +GA$$$"}}T2	h//  "W X X	 , $J
3FVW!1i.-r    Nc           	         [        U5      [        U 5      :w  a#  [        S[        U 5       S[        U5       35      eU S   R                  US   SS9u  pV[        U SS USS 5       HC  u  pxUR                  USS9u  pUSSS	24==   U	SSS	24   -  ss'   US
==   U	S
   -  ss'   Xj-  nME     U R                  S:X  a  USSS	24==   [        U 5      S-
  -  ss'   U R                  5       XV'   U(       a  [        R                  " USS5      nUb  U(       a  [        R                  " USS5      n[        R                  " U5      S[        R                  " US   5      4;  a<  [        S[        R                  " U5       S[        R                  " US   5       35      eUS==   U-  ss'   U(       a&  U(       d  [        S5      eUS-  R                  S5      n[        R                  " US   5      (       d  [        U5      nU$ )a  
Parameters
----------
X : tuple (X0, X1, ...) of length equal to the number of colormaps
    X0, X1 ...:
    float or int, `~numpy.ndarray` or scalar
    The data value(s) to convert to RGBA.
    For floats, *Xi...* should be in the interval ``[0.0, 1.0]`` to
    return the RGBA values ``X*100`` percent along the Colormap line.
    For integers, *Xi...*  should be in the interval ``[0, self[i].N)`` to
    return RGBA values *indexed* from colormap [i] with index ``Xi``, where
    self[i] is colormap i.
alpha : float or array-like or None
    Alpha must be a scalar between 0 and 1, a sequence of such
    floats with shape matching *Xi*, or None.
bytes : bool, default: False
    If False (default), the returned RGBA values will be floats in the
    interval ``[0, 1]`` otherwise they will be `numpy.uint8`\s in the
    interval ``[0, 255]``.
clip : bool, default: True
    If True, clip output to 0 to 1

Returns
-------
Tuple of RGBA values if X[0] is scalar, otherwise an array of
RGBA values with a shape of ``X.shape + (4, )``.
z?For the selected colormap the data must have a first dimension z, not r   Fr  r   N.r   ).r   r  r7   r6   does not match that of X[0] r7  z_clip cannot be false while bytes is true as uint8 does not support values below 0 or above 255.r   rB  )rZ   rh   r+  r  r  r[  r   r  r   r@  r   r   )r   r,  r   r*  r  r   rG  r   xxsub_rgbasub_mask_bads              r   r-  MultivarColormap.__call__  s   : q6SYQt9+VCF8-. . a33AaD3Fab1QR5)EA%&%9%9"E%9%J"HbqbMXc2A2g..MLHV,,L$H	 *   J.bqbMSY]*M774A&Dq!,xxr288AaD>&:: 8%8I J..0hhqtn-=?@ @ MU"M %& & 3J&&w/D{{1Q4  ;Dr    c                 "    U R                  5       $ )z&Return a copy of the multivarcolormap.r  rL   s    r   r   MultivarColormap.copy\  r  r    c                 <   U R                   nUR                  U5      nUR                  R                  U R                  5        U R                   Vs/ s H  o3R                  5       PM     snUl        [        R
                  " U R                  5      Ul        U$ s  snf r   )r   rJ  rK  rL  r  r   r   r  )r   rN  rO  cms       r   rP  MultivarColormap.__copy__`  sq    nn[[%
""4==159__ E_r_ E
!wwt~~6
 !Fs   Bc                    [        U[        5      (       d  g[        U 5      [        U5      :w  a  g[        X5       H  u  p#X#:w  d  M    g   [	        U R
                  UR
                  :H  5      (       d  gU R                  UR                  :w  a  ggNFT)r   r   rZ   r  r   r  r  )r   rV  c0r   s       r   rW  MultivarColormap.__eq__h  sv    %!122t9E
"$&FBx ' 4>>U__455  E$:$::r    c                      U R                   U   $ r   r  rQ   s     r   rS   MultivarColormap.__getitem__v  s    t$$r    c              #   :   #    U R                    H  nUv   M	     g 7fr   r  r   r   s     r   rW   MultivarColormap.__iter__y  s     AG !s   c                 ,    [        U R                  5      $ r   )rZ   r  rL   s    r   r[   MultivarColormap.__len__}  s    4??##r    c                     U R                   $ r   r  rL   s    r   re   MultivarColormap.__str__  s    yyr    c                 B    [         R                  " U R                  5      $ rZ  )r   r   r  rL   s    r   r[  MultivarColormap.get_bad  s    xx''r    c                 ,   [         R                  " U5      (       a  [        U5      [        U 5      :w  a  [        S[        U 5       35      eU R	                  5       n[        U5       H*  u  p4Uc  M
  X   R                  U5      UR                  U'   M,     U$ )aa  
Return a new colormap with *lutshape* entries.

Parameters
----------
lutshape : tuple of (`int`, `None`)
    The tuple must have a length matching the number of variates.
    For each element in the tuple, if `int`, the corresponding colorbar
    is resampled, if `None`, the corresponding colorbar is not resampled.

Returns
-------
MultivarColormap
zlutshape must be of length )r   r   rZ   rh   r   r  r  r  )r   lutshaper  r
  ss        r   r  MultivarColormap.resampled  s~      {{8$$HT(B:3t9+FGG99;h'DA})-):):1)=##A& ( r    rn  c                   U R                  5       nUb  [        U5      Ul        Ubp  [        R                  " U5      (       a  [        U5      [        U5      :w  a  [        S[        U5       S35      e[        XB5       H  u  pVUR                  U5        M     Ubp  [        R                  " U5      (       a  [        U5      [        U5      :w  a  [        S[        U5       S35      e[        XC5       H  u  pVUR                  U5        M     U$ )a*  
Return a copy of the `MultivarColormap` with modified out-of-range attributes.

The *bad* keyword modifies the copied `MultivarColormap` while *under* and
*over* modifies the attributes of the copied component colormaps.
Note that *under* and *over* colors are subject to the mixing rules determined
by the *combination_mode*.

Parameters
----------
bad: :mpltype:`color`, default: None
    If Matplotlib color, the bad value is set accordingly in the copy

under tuple of :mpltype:`color`, default: None
    If tuple, the `under` value of each component is set with the values
    from the tuple.

over tuple of :mpltype:`color`, default: None
    If tuple, the `over` value of each component is set with the values
    from the tuple.

Returns
-------
MultivarColormap
    copy of self with attributes set

zH*under* must contain a color for each scalar colormap i.e. be of length .zG*over* must contain a color for each scalar colormap i.e. be of length )
r   ri   r  r   r   rZ   rh   r  rf  rl  )r   ro  rp  rq  rv  r   r  s          r   rw  MultivarColormap.with_extremes  s    8 ?&s|F;;u%%Us6{)B  "77:6{m1"F G G  .DAKKN /;;t$$D	S[(@  "77:6{m1"F G G  -DAJJqM .r    c                     U R                   $ r   )r	  rL   s    r   r  !MultivarColormap.combination_mode  s    %%%r    c                    [         R                  " [         R                  " SS[        S   5      [        S   S45      n[         R                  " [        S   [        U 5      -  [        S   S4[         R                  S9n[        U 5       H+  u  p4U" USS9X#[        S   -  US-   [        S   -  2SS24'   M-     [        R                  " 5       nU R                  S-   nS	[        R                   S
3n[        5       nUR                  SU5        UR                  SU5        UR                  SU5        UR                  SU5        [        R                   " U5      R#                  USUS9  UR%                  5       $ )r  r   r   r   r  Tr  Nz multivariate colormapr  r  r  r  r  r  r  r  )r   r   r
  r  r   rZ   rB  r  r  r  ra   r   r  r   r  r   r  r  r  )	r   r,  r  r
  r   r  r  r  r  s	            r   r  MultivarColormap._repr_png_  sF   GGBKK1nQ&78!/!2A 68>!,SY6q8I1M "*dODAEFqPTEUF^A&&!^A->'>>AB $JJL			4400HI)%(.6*V,$$Yug$N!!##r    c                 ~    SR                  U R                   Vs/ s H  oR                  5       PM     sn5      $ s  snf )z8Generate an HTML representation of the MultivarColormap.r   )rd   r  r  r   s     r   r  MultivarColormap._repr_html_  s+    wwAAABBAs   :)r  r	  r  r&  ra   )zmultivariate colormapr  )r*   r+   r,   r-   rs   r   r-  r   rP  rW  rS   rW   r[   re   r[  r  rw  propertyr  r  r  r.   r7   r    r   r   r     so    ".HDL%$(0 $(t$ -^ & &$&Cr    r   c                       \ rS rSrSr  SS jrSS jr\S 5       rS r	S r
S	 rS
 rSS jrSS jrS rSSSSS.S jrS r\S 5       r\S 5       rS rS rS rS rS rSrg)BivarColormapi  z
Base class for all bivariate to RGBA mappings.

Designed as a drop-in replacement for Colormap when using a 2D
lookup table. To be used with `~matplotlib.cm.ScalarMappable`.
c                    XPl         [        U5      U l        [        U5      U l        [        R
                  " / SQUS9  X0l        SU l        SU l        SU l	        SU l
        [        US   5      [        US   5      4U l        g	)
a  
Parameters
----------
N : int, default: 256
    The number of RGB quantization levels along the first axis.
M : int, default: 256
    The number of RGB quantization levels along the second axis.
shape : {'square', 'circle', 'ignore', 'circleignore'}

    - 'square' each variate is clipped to [0,1] independently
    - 'circle' the variates are clipped radially to the center
      of the colormap, and a circular mask is applied when the colormap
      is displayed
    - 'ignore' the variates are not clipped, but instead assigned the
      'outside' color
    - 'circleignore' a circular mask is applied, but the data is not
      clipped and instead assigned the 'outside' color

origin : (float, float), default: (0,0)
    The relative origin of the colormap. Typically (0, 0), for colormaps
    that are linear on both axis, and (.5, .5) for circular colormaps.
    Used when getting 1D colormaps from 2D colormaps.
name : str, optional
    The name of the colormap.
squarecircler2  circleignorer   r   )r   r   r   r   Fr   r   r   N)ra   r   r  Mr	   r  _shaper  _rgba_outsider%  r&  r   _origin)r   r  r>  r   originra   s         r   r   BivarColormap.__init__  sv    8 	QQIQVW-1fQi(%q	*:;	(r    Nc                    [        U5      S:w  a  [        S[        U5       35      eU R                  (       d  U R                  5         [        R
                  R                  US   SS9n[        R
                  R                  US   SS9nU R                  XE45        UR                  R                  (       d7  UR                  5       R                  UR                  R                  5       5      nUR                  R                  (       d7  UR                  5       R                  UR                  R                  5       5      nUR                  R                  S:X  a,  X@R                  -  nU R                  S-
  XDU R                  :H  '   UR                  R                  S:X  a,  XPR                  -  nU R                  S-
  XUU R                  :H  '   US:  US:  -  X@R                  :  -  XPR                  :  -  n[        R
                  R!                  U5      (       a  UR"                  O[        R$                  " U5      n[        R
                  R!                  U5      (       a  UR"                  O[        R$                  " U5      nXx-  n	[        R&                  " SS	9   UR)                  [*        5      nUR)                  [*        5      nS
S
S
5        XE4 H  n
SX'   SX'   M     U R,                  XE4   n[        R.                  " US   5      (       a  [        R0                  " U5      nU R2                  X'   U R4                  X'   U(       a"  US-  R)                  [        R6                  5      nUb  [        R8                  " USS5      nU(       a  US-  n[        R:                  " U5      S[        R:                  " U5      4;  a9  [        S[        R:                  " U5       S[        R:                  " U5       35      eX+S'   [        R                  " U R4                  5      S:H  R=                  5       (       a  SX'   [        R>                  " US   5      (       d  [A        U5      nU$ ! , (       d  f       GN= f)ar  
Parameters
----------
X : tuple (X0, X1), X0 and X1: float or int or array-like
    The data value(s) to convert to RGBA.

    - For floats, *X* should be in the interval ``[0.0, 1.0]`` to
      return the RGBA values ``X*100`` percent along the Colormap.
    - For integers, *X* should be in the interval ``[0, Colormap.N)`` to
      return RGBA values *indexed* from the Colormap with index ``X``.

alpha : float or array-like or None, default: None
    Alpha must be a scalar between 0 and 1, a sequence of such
    floats with shape matching X0, or None.
bytes : bool, default: False
    If False (default), the returned RGBA values will be floats in the
    interval ``[0, 1]`` otherwise they will be `numpy.uint8`\s in the
    interval ``[0, 255]``.

Returns
-------
Tuple of RGBA values if X is scalar, otherwise an array of
RGBA values with a shape of ``X.shape + (4, )``.
r   zBFor a `BivarColormap` the data must have a first dimension 2, not r   Tr0  r   r1  r2  r3  Nr   r7   r6  r  r7  r8  )!rZ   rh   r%  r9  r   r   r   _clipr   r:  r;  r<  r=  r   r  r>  r   r   r>  r?  r@  r   rA  isscalarr   r@  r  rB  r  r   r   r   r   )r   r,  r   r*  X0X1mask_outside
mask_bad_0
mask_bad_1rG  X_partr   s               r   r-  BivarColormap.__call__  sH   4 q6Q;a&#$ $ ||JJLUU[[1D[)UU[[1D[)

B8 xx  ##BHH$9$9$;<Bxx  ##BHH$9$9$;<B88==C&&LB#vvzBTVV|88==C&&LB#vvzBTVV| Q26*bFFl;rVV|L " 3 3RWW"
 " 3 3RWW"
*[[*3B3B + hF#$F  F  yy ;;qt774=D!//3J&&rxx0DGGE1a(Exxr288B<&88 8%8I J..0hhrl^=> > "M(A-2244!-{{1Q4  ;DC +*s   +Q  
Q/c                    U R                   (       d  U R                  5         [        R                  " U R                  5      nU R
                  S:X  d  U R
                  S:X  a  [        R                  " SSU R                  5      n[        R                  " SSU R                  5      nUS-  SS2[        R                  4   US-  [        R                  SS24   -   nUS:  nSXS4'   U$ )	a  
For external access to the lut, i.e. for displaying the cmap.
For circular colormaps this returns a lut with a circular mask.

Internal functions (such as to_rgb()) should use _lut
which stores the lut without a circular mask
A lut without the circular mask is needed in to_rgb() because the
conversion from floats to ints results in some some pixel-requests
just outside of the circular mask

r;  r<  r   r   r   Nr   r   )
r%  r9  r   r   rA  r   r
  r  r>  newaxis)r   r  r   m	radii_sqrrI  s         r   r  BivarColormap.lut  s     ||JJLggdii ::!TZZ>%AB466*AB466*AAq"**}-Arzz1}0EEI$q=L#$Ca 
r    c                    U R                   nUR                  U5      nUR                  R                  U R                  5        [        R
                  " U R                  5      Ul        [        R
                  " U R                  5      Ul        U R                  Ul	        U R                  (       a%  [        R
                  " U R                  5      Ul        U$ r   )r   rJ  rK  rL  r   r   r@  r  r   r?  r%  rA  rM  s      r   rP  BivarColormap.__copy__  s    nn[[%
""4==1#%774+=+=#>
 !wwt~~6
 JJ
<< ggdii0JOr    c                    [        U[        5      (       d  gU R                  (       d  U R                  5         UR                  (       d  UR                  5         [        R
                  " U R                  UR                  5      (       d  g[        R
                  " U R                  UR                  5      (       d  g[        R
                  " U R                  UR                  5      (       d  gU R                  UR                  :w  a  ggr  )
r   r7  r%  r9  r   rT  rA  r  r@  r   rU  s     r   rW  BivarColormap.__eq__  s    %//||JJL}}KKM~~dii44~~dnneoo>>~~d00%2E2EFF::$r    c                     U R                   $ rZ  )r  rL   s    r   r[  BivarColormap.get_bad  s    ~~r    c                     U R                   $ )z&Get the color for out-of-range values.)r@  rL   s    r   get_outsideBivarColormap.get_outside  s    !!!r    c           	         [         R                  " U5      (       a  [        U5      S:w  a  [        S5      eUS   US   /nUS   b	  US   S:X  a  U R                  US'   US   b	  US   S:X  a  U R
                  US'   SS/nUS   S:  a&  SUS'   US   * US'   US   S:X  a  U R                  US'   US   S:  a&  SUS'   US   * US'   US   S:X  a  U R
                  US'   [         R                  SSUS   S-  2SSUS   S-  24   u  pEUS   (       a  USSS	2SS24   nUS   (       a  USS2SSS	24   nU R                  nS
U l        U(       a/  U " XT45      n[        XpR                  UU R                  SSS	2   S9nO(U " XE45      n[        XpR                  UU R                  S9nX`l        U R                  Ul        U R                  Ul        U$ )a3  
Return a new colormap with *lutshape* entries.

Note that this function does not move the origin.

Parameters
----------
lutshape : tuple of ints or None
    The tuple must be of length 2, and each entry is either an int or None.

    - If an int, the corresponding axis is resampled.
    - If negative the corresponding axis is resampled in reverse
    - If -1, the axis is inverted
    - If 1 or None, the corresponding axis is not resampled.

transposed : bool, default: False
    if True, the axes are swapped after resampling

Returns
-------
BivarColormap
r   zlutshape must be of length 2r   r   NFTy              ?r   r:  )ra   r   rB  )r   r   rZ   rh   r  r>  mgridr?  BivarColormapFromImagera   rB  r  r@  )	r   r)  
transposedinvertedx_0x_1shape_memorynew_lutr  s	            r   r  BivarColormap.resampled  s   0 {{8$$H(:;<<QK!-A;(1+"2&&HQKA;(1+"2&&HQK5>A;?HQK#A;,HQK{a"ffA;?HQK#A;,HQK{a"ff88Aa!r!12Aa!r9I4JJKA;ddAg,CA;a2g,C
 {{C:&G-gII4@59[[25FHH C:&G-gII4@59[[BH #!^^!%!3!3r    c                 R    U(       a  SOSnU(       a  SOSnU R                  X445      $ )z#
Reverses both or one of the axis.
r   r   r  )r   axis_0axis_1r_0r_1s        r   r  BivarColormap.reversed  s'     bb~~sj))r    c                 "    U R                  SSS9$ )z;
Transposes the colormap by swapping the order of the axis
NNT)r_  rg  rL   s    r   r_  BivarColormap.transposed  s     ~~lt~<<r    )ro  outsider   rB  c                    U R                  5       nUb  [        U5      Ul        Ub  [        U5      Ul        Ub  [        R
                  " / SQUS9  X5l        Ub!  [        US   5      [        US   5      4Ul        U$ )a  
Return a copy of the `BivarColormap` with modified attributes.

Note that the *outside* color is only relevant if `shape` = 'ignore'
or 'circleignore'.

Parameters
----------
bad : None or :mpltype:`color`
    If Matplotlib color, the *bad* value is set accordingly in the copy

outside : None or :mpltype:`color`
    If Matplotlib color and shape is 'ignore' or 'circleignore', values
    *outside* the colormap are colored accordingly in the copy

shape : {'square', 'circle', 'ignore', 'circleignore'}

    - If 'square' each variate is clipped to [0,1] independently
    - If 'circle' the variates are clipped radially to the center
      of the colormap, and a circular mask is applied when the colormap
      is displayed
    - If 'ignore' the variates are not clipped, but instead assigned the
      *outside* color
    - If 'circleignore' a circular mask is applied, but the data is not
      clipped and instead assigned the *outside* color

origin : (float, float)
    The relative origin of the colormap. Typically (0, 0), for colormaps
    that are linear on both axis, and (.5, .5) for circular colormaps.
    Used when getting 1D colormaps from 2D colormaps.

Returns
-------
BivarColormap
    copy of self with attributes set
r9  r=  r   r   )	r   ri   r  r@  r	   r  r?  r   rA  )r   ro  rp  r   rB  rv  s         r   rw  BivarColormap.with_extremes  s|    J ?&s|F#*7#3F M%*,!M#F1I.fQi0@AFNr    c                     [        S5      er|  r}  rL   s    r   r9  BivarColormap._initD  r  r    c                     U R                   $ r   )r?  rL   s    r   r   BivarColormap.shapeH  s    {{r    c                     U R                   $ r   )rA  rL   s    r   rB  BivarColormap.originL  s    ||r    c                 d   U R                   S:X  a_  [        XR                  U R                  45       H9  u  p#SX"S:  '   UR                  R
                  S:X  a	  SX"S:  '   M/  US-
  X"U:  '   M;     gU R                   S:X  a\  [        XR                  U R                  45       H6  u  p#SX"S:  '   UR                  R
                  S:X  a	  SX"S:  '   M/  SX"U:  '   M8     gU R                   S:X  d  U R                   S:X  a  U H(  nUR                  R
                  S:w  d  M  [        S	5      e   US   S
-
  S-  US   S
-
  S-  -   nUS:  nU R                   S:X  aJ  S[        R                  " XE   5      -  nUS   U   S
-
  U-  S
-   US   U'   US   U   S
-
  U-  S
-   US   U'   gSUS   U'   SUS   U'   gg)a  
For internal use when applying a BivarColormap to data.
i.e. cm.ScalarMappable().to_rgba()
Clips X[0] and X[1] according to 'self.shape'.
X is modified in-place.

Parameters
----------
X: np.array
    array of floats or ints to be clipped
shape : {'square', 'circle', 'ignore', 'circleignore'}

    - If 'square' each variate is clipped to [0,1] independently
    - If 'circle' the variates are clipped radially to the center
      of the colormap.
      It is assumed that a circular mask is applied when the colormap
      is displayed
    - If 'ignore' the variates are not clipped, but instead assigned the
      'outside' color
    - If 'circleignore' a circular mask is applied, but the data is not clipped
      and instead assigned the 'outside' color

r:  r   r1  r   r2  r   r;  r<  zJCircular bivariate colormaps are only implemented for use with with floats      ?r   g      ?N)	r   r  r  r>  r   r   r~  r   sqrt)r   r,  rL  mxrQ  rI  
overextends          r   rE  BivarColormap._clipP  s   0 ::!!!ffdff%56
%&z"<<$$+)*FA:&+-6FR<( 7 ZZ8#!!ffdff%56
%'z"<<$$+)+FA:&+-FR<( 7 ZZ8#tzz^'C<<$$+-@A A 
 1a1Q4#:/9I$t+LzzX%)@!AA
&'d<&83&>*%Ls%R!\"&'d<&83&>*%Ls%R!\"%'!\"%'!\" (Dr    c                    U R                   (       d  U R                  5         US:X  a{  [        U R                  S   U R                  -  5      nX R                  S-
  :  a  U R                  S-
  nU R
                  SS2U4   n[        X0R                   S3U R                  S9nOUS:X  a{  [        U R                  S   U R                  -  5      nXPR                  S-
  :  a  U R                  S-
  nU R
                  USS24   n[        X0R                   S3U R                  S9nO[        SU< 35      eU R                  Ul
        U R                  S;   a6  UR                  U R                  5        UR                  U R                  5        U$ )	z6Creates and returns a colorbar along the selected axisr   r   N_0r  _1z2only 0 or 1 are valid keys for BivarColormap, not )r2  r<  )r%  r9  r   rA  r>  rA  r  ra   r  rP   r  r   rl  r@  rf  )r   rR   origin_1_as_int	one_d_lutr  origin_0_as_ints         r   rS   BivarColormap.__getitem__  sN   ||JJL19!$,,q/$&&"89O)"&&&(		!_"45I%i26F$&&QHQY!$,,q/$&&"89O)"&&&(		/1"45I%i26F$&&QH AAEJ K K!^^::33d001t112r    c                 `   U R                   (       d  U R                  5         U R                  nUR                  S   [        :  a3  [
        R                  " U[        UR                  S   -  SS9SS2SS24   nUR                  S   [        :  a3  [
        R                  " U[        UR                  S   -  SS9SS2SS24   nUSSS2SS2SS24   S-  R                  [
        R                  5      n[        R                  " 5       nU R                  S-   nS	[        R                   S
3n[        5       nUR                  SU5        UR                  SU5        UR                  SU5        UR                  SU5        [         R"                  " U5      R%                  USUS9  UR'                  5       $ )z3Generate a PNG representation of the BivarColormap.r   )repeatsr   Nr4   r   r   r   z BivarColormapr  r  r  r  r  r  r  r  )r%  r9  r  r   _BIVAR_REPR_PNG_SIZEr   repeatr@  rB  r  r  ra   r   r  r   r  r   r  r  r  )r   r  r  r  r  r  s         r   r  BivarColormap._repr_png_  sq   ||JJL<<?11YYv';V\\!_'L$%''+tQw0F <<?11YYv';V\\!_'L$%''($3$w0F 2q!$s*22288<JJL			,,00HI)%(.6*V,$$Yug$N!!##r    c                 <   U R                  5       n[        R                  " U5      R                  S5      nS nSU R                   SU R                   SU R                   SU S[
        S-    S	U" U R                  5       5       S
U" U R                  5       5       S3$ )r  r  c                 (    [        U SS9nSU SU S3$ r  r  r  s     r   r  .BivarColormap._repr_html_.<locals>.color_block  r  r    r  r  z BivarColormap" title="r  r  r   r  z- outside</div><div style="float: right;">bad r  )r  r  r  r  ra   r  rZ  r[  r  s       r   r  BivarColormap._repr_html_  s    OO%	%%i077@
	?99+ & 		{ #)) %..8\ :2145 6- t//123 4 #4<<>23! 	 r    c                 "    U R                  5       $ r  r  rL   s    r   r   BivarColormap.copy  r  r    )	r>  r  r%  rA  r  r@  r?  r&  ra   )r4   r4   r:  r   r   zbivariate colormaprS  F)TT)r*   r+   r,   r-   rs   r   r-  r5  r  rP  rW  r[  rZ  r  r  r_  rw  r9  r   rB  rE  rS   r  r  r   r.   r7   r    r   r7  r7    s     =C**(X_B  .
$"DL*= $(T$ 1f9    6(p4$2 @r    r7  c                   :   ^  \ rS rSrSr  SU 4S jjrS rSrU =r$ )SegmentedBivarColormapi  a  
BivarColormap object generated by supersampling a regular grid.

Parameters
----------
patch : np.array
    Patch is required to have a shape (k, l, 3), and will get supersampled
    to a lut of shape (N, N, 4).
N : int
    The number of RGB quantization levels along each axis.
shape : {'square', 'circle', 'ignore', 'circleignore'}

    - If 'square' each variate is clipped to [0,1] independently
    - If 'circle' the variates are clipped radially to the center
      of the colormap, and a circular mask is applied when the colormap
      is displayed
    - If 'ignore' the variates are not clipped, but instead assigned the
      'outside' color
    - If 'circleignore' a circular mask is applied, but the data is not clipped

origin : (float, float)
    The relative origin of the colormap. Typically (0, 0), for colormaps
    that are linear on both axis, and (.5, .5) for circular colormaps.
    Used when getting 1D colormaps from 2D colormaps.

name : str, optional
    The name of the colormap.
c                 Z   > [         R                  " SUS9  Xl        [        TU ]  X"X4US9  g )N)NNr   )patchr  )r	   r  r  r   r   )r   r  r  r   rB  ra   r   s         r   r   SegmentedBivarColormap.__init__  s,    6
u48r    c           	      P   U R                   R                  n[        R                  " US   US   S45      nU R                   US S 2S S 2S S24'   SUS S 2S S 2S4'   [        R
                  R                  5       R                  SS5      R                  U R                  US   S-
  -  U R                  US   S-
  -  5      n[        R                  " U R                  U R                  S45      U l
        [        R                  " X R                  U[        R                  SSS9  SU l        g )	Nr   r   r   r   g      F)resampler   T)r  r   r   emptyr   
transformsAffine2D	translater   r  rA  r   r  BILINEARr%  )r   r*  _patch	transforms       r   r9  SegmentedBivarColormap._init  s    JJ1Q41q/*::q!RaRxq!QwNN++-77dC!&tvv1':DFFadQh<O!P 	HHdffdffa01			9foo!&a	1r    )r%  rA  r  )r4   r:  r  zsegmented bivariate colormap	r*   r+   r,   r-   rs   r   r9  r.   r/   r0   s   @r   r  r    s     : =C49 r    r  c                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )r^  i  ar  
BivarColormap object generated by supersampling a regular grid.

Parameters
----------
lut : nparray of shape (N, M, 3) or (N, M, 4)
    The look-up-table
shape: {'square', 'circle', 'ignore', 'circleignore'}

    - If 'square' each variate is clipped to [0,1] independently
    - If 'circle' the variates are clipped radially to the center
      of the colormap, and a circular mask is applied when the colormap
      is displayed
    - If 'ignore' the variates are not clipped, but instead assigned the
      'outside' color
    - If 'circleignore' a circular mask is applied, but the data is not clipped

origin: (float, float)
    The relative origin of the colormap. Typically (0, 0), for colormaps
    that are linear on both axis, and (.5, .5) for circular colormaps.
    Used when getting 1D colormaps from 2D colormaps.
name : str, optional
    The name of the colormap.

c                 B  > [         R                  " USS9nUR                  S:w  d  UR                  S   S;  a  [	        SS5      eUR
                  [         R                  :X  a"  UR                  [         R                  5      S-  nUR                  S   S:X  aW  [         R                  " UR                  S	   UR                  S
   S4UR
                  S9nXS S 2S S 2S S24'   SUS S 2S S 2S4'   UnXl
        [        TU ]1  UR                  S	   UR                  S
   X#US9  g )NTr0  r   r   r   z8The lut must be an array of shape (n, m, 3) or (n, m, 4)z& or a PIL.image encoded as RGB or RGBAr   r   r   r   r  r   r  )r   r   r   r   rh   r   rB  r@  float32r  rA  r   r   )r   r  r   rB  ra   rd  r   s         r   r   BivarColormapFromImage.__init__-  s     hhs&88q=CIIaL6WEG G 99 **RZZ(,C99Q<1hh		!ciilA>ciiPG #Aq"1"H!GAq!GC	1syy|UNr    c                     SU l         g )NT)r%  rL   s    r   r9  BivarColormapFromImage._initC  s	    r    )r%  rA  )r:  r  z
from imager  r0   s   @r   r^  r^    s    4O, r    r^  c                       \ rS rSrSrSS jr\S 5       r\R                  S 5       r\S 5       r	\	R                  S 5       r	\S	 5       r
\
R                  S
 5       r
S r\S 5       rSS jrS rS rS rS rSrg)	NormalizeiG  a  
A class which, when called, maps values within the interval
``[vmin, vmax]`` linearly to the interval ``[0.0, 1.0]``. The mapping of
values outside ``[vmin, vmax]`` depends on *clip*.

Examples
--------
::

    x = [-2, -1, 0, 1, 2]

    norm = mpl.colors.Normalize(vmin=-1, vmax=1, clip=False)
    norm(x)  # [-0.5, 0., 0.5, 1., 1.5]
    norm = mpl.colors.Normalize(vmin=-1, vmax=1, clip=True)
    norm(x)  # [0., 0., 0.5, 1., 1.]

See Also
--------
:ref:`colormapnorms`
Nc                     [        U5      U l        [        U5      U l        X0l        SU l        [
        R                  " S/S9U l        g)a  
Parameters
----------
vmin, vmax : float or None
    Values within the range ``[vmin, vmax]`` from the input data will be
    linearly mapped to ``[0, 1]``. If either *vmin* or *vmax* is not
    provided, they default to the minimum and maximum values of the input,
    respectively.

clip : bool, default: False
    Determines the behavior for mapping values outside the range
    ``[vmin, vmax]``.

    If clipping is off, values outside the range ``[vmin, vmax]`` are
    also transformed, resulting in values outside ``[0, 1]``.  This
    behavior is usually desirable, as colormaps can mark these *under*
    and *over* values with specific colors.

    If clipping is on, values below *vmin* are mapped to 0 and values
    above *vmax* are mapped to 1. Such values become indistinguishable
    from regular boundary values, which may cause misinterpretation of
    the data.

Notes
-----
If ``vmin == vmax``, input data will be mapped to 0.
Nchanged)signals)r   _vmin_vmaxrE  _scaler   CallbackRegistry	callbacks)r   vminvmaxr  s       r   r   Normalize.__init__]  s<    8 't,
&t,

//Dr    c                     U R                   $ r   r  rL   s    r   r  Normalize.vmin      zzr    c                 f    [        U5      nXR                  :w  a  Xl        U R                  5         g g r   )r   r  _changedr   r%   s     r   r  r    )    !%(JJJMMO r    c                     U R                   $ r   r  rL   s    r   r  Normalize.vmax  r  r    c                 f    [        U5      nXR                  :w  a  Xl        U R                  5         g g r   )r   r  r  r  s     r   r  r    r  r    c                     U R                   $ r   )rE  rL   s    r   r  Normalize.clip  r  r    c                 P    XR                   :w  a  Xl         U R                  5         g g r   )rE  r  r  s     r   r  r    s    JJJMMO r    c                 :    U R                   R                  S5        g)zf
Call this whenever the norm is changed to notify all the
callback listeners to the 'changed' signal.
r  N)r  processrL   s    r   r  Normalize._changed  s    
 	y)r    c                    [         R                  " U 5      (       + nU(       a  U /n [         R                  " U 5      n[         R                  " U[         R                  5      (       d  UR
                  [         R                  L a%  [         R                  " U[         R                  5      n[         R                  R                  U 5      n[         R                  " U 5      n[         R                  R                  XCUSS9nXQ4$ )a.  
Homogenize the input *value* for easy and efficient normalization.

*value* can be a scalar or sequence.

Parameters
----------
value
    Data to normalize.

Returns
-------
result : masked array
    Masked array with the same shape as *value*.
is_scalar : bool
    Whether *value* is a scalar.

Notes
-----
Float dtypes are preserved; integer types with two bytes or smaller are
converted to np.float32, and larger types are converted to np.float64.
Preserving float32 when possible, and using in-place operations,
greatly improves speed for large arrays.
T)r   r   r   )r   r   min_scalar_type
issubdtypeintegerr  bool_promote_typesr  r   getmaskr   r   )r%   	is_scalarr   r   r  r   s         r   process_valueNormalize.process_value  s    4 E**	GE""5)==

++uzzRXX/E$$UBJJ7E uu}}U#zz% TEE  r    c                    Uc  U R                   nU R                  U5      u  p4U R                  b  U R                  c  U R	                  U5        U R                  U R                  5      u  u  pVU R                  U R                  5      u  u  pvXW:X  a  UR                  S5        OXW:  a  [        S5      eU(       aa  [        R                  R                  U5      n[        R                  R                  [        R                   " UR                  U5      XW5      US9nUR                  n	X-  n	XU-
  -  n	[        R                  R                  XR                  SS9nU(       a  US   nU$ )a  
Normalize the data and return the normalized data.

Parameters
----------
value
    Data to normalize.
clip : bool, optional
    See the description of the parameter *clip* in `.Normalize`.

    If ``None``, defaults to ``self.clip`` (which defaults to
    ``False``).

Notes
-----
If not already initialized, ``self.vmin`` and ``self.vmax`` are
initialized using ``self.autoscale_None(value)``.
r   /minvalue must be less than or equal to maxvaluer   Fr   r   )r  r  r  r  autoscale_Nonefillrh   r   r   r  r   filledr  r   )
r   r%   r  r   r  r  _r  r   resdats
             r   r-  Normalize.__call__  s%   & <99D ..u599		 1'''		2
''		2
<KKN[NOOuu}}V,RWWV]]4-@$%M*. % 0 [[FNFd{#FUU[[kk[FFAYFr    c                 V   U R                  5       (       d  [        S5      eU R                  U R                  5      u  u  p#U R                  U R                  5      u  u  pC[
        R                  " U5      (       a(  [
        R                  R                  U5      nX%XB-
  -  -   $ X!XB-
  -  -   $ )z
Maps the normalized value (i.e., index in the colormap) back to image
data value.

Parameters
----------
value
    Normalized value.
/Not invertible until both vmin and vmax are set)	scaledrh   r  r  r  r   r   r   r   )r   r%   r  r  r  r   s         r   inverseNormalize.inverse  s     {{}}NOO''		2
''		2
;;u%%--&C---4;///r    c                     U R                   R                  5          S=U l        U l        U R	                  U5        SSS5        U R                  5         g! , (       d  f       N= f)z&Set *vmin*, *vmax* to min, max of *A*.N)r  blockedr  r  r  r  r   As     r   	autoscaleNormalize.autoscale	  sI    ^^##% %)(DI	"	 &
 	 &%s    A
A"c                    [         R                  " U5      n[        U[         R                  R                  5      (       a6  UR
                  SL d  UR
                  R                  (       d  UR                  nU R                  c&  UR                  (       a  UR                  5       U l        U R                  c(  UR                  (       a  UR                  5       U l        ggg)zDIf *vmin* or *vmax* are not set, use the min/max of *A* to set them.FN)r   
asanyarrayr   r   MaskedArrayr   r   r  r  sizeminr  r   r  s     r   r  Normalize.autoscale_None	  s    MM!a**++vvaffllFF99DI99DI "(r    c                 H    U R                   SL=(       a    U R                  SL$ )z.Return whether *vmin* and *vmax* are both set.Nr  r  rL   s    r   r  Normalize.scaled)	  s    yy$>$)>>r    )rE  r  r  r  r  r  r  NNFr   )r*   r+   r,   r-   rs   r   r5  r  setterr  r  r  r  r  r-  r  r  r  r  r.   r7   r    r   r  r  G  s    * ED   
[[    
[[    
[[ 
* %! %!N-^0* ?r    r  c                   |   ^  \ rS rSrS	U 4S jjr\S 5       r\R                  S 5       rU 4S jrS
S jr	S r
SrU =r$ )TwoSlopeNormi.	  c                    > [         TU ]  X#S9  Xl        Ub  Ub  X:  a  [        S5      eUb  Ub  X::  a  [        S5      eggg)a  
Normalize data with a set center.

Useful when mapping data with an unequal rates of change around a
conceptual center, e.g., data that range from -2 to 4, with 0 as
the midpoint.

Parameters
----------
vcenter : float
    The data value that defines ``0.5`` in the normalization.
vmin : float, optional
    The data value that defines ``0.0`` in the normalization.
    Defaults to the min value of the dataset.
vmax : float, optional
    The data value that defines ``1.0`` in the normalization.
    Defaults to the max value of the dataset.

Examples
--------
This maps data value -4000 to 0., 0 to 0.5, and +10000 to 1.0; data
between is linearly interpolated::

    >>> import matplotlib.colors as mcolors
    >>> offset = mcolors.TwoSlopeNorm(vmin=-4000.,
    ...                               vcenter=0., vmax=10000)
    >>> data = [-4000., -2000., 0., 2500., 5000., 7500., 10000.]
    >>> offset(data)
    array([0., 0.25, 0.5, 0.625, 0.75, 0.875, 1.0])
r  Nz2vmin, vcenter, and vmax must be in ascending order)r   r   _vcenterrh   )r   vcenterr  r  r   s       r   r   TwoSlopeNorm.__init__/	  si    @ 	d.4#3 / 0 04#3 / 0 0 9H#3r    c                     U R                   $ r   r  rL   s    r   r  TwoSlopeNorm.vcenterX	      }}r    c                 P    XR                   :w  a  Xl         U R                  5         g g r   )r  r  r  s     r   r  r  \	  s    MM!!MMMO "r    c                 :  > [         TU ]  U5        U R                  U R                  :  a+  U R                  U R                  U R                  -
  -
  U l        U R                  U R                  ::  a,  U R                  U R                  U R                  -
  -   U l        gg)z
Get vmin and vmax.

If vcenter isn't in the range [vmin, vmax], either vmin or vmax
is expanded so that vcenter lies in the middle of the modified range
[vmin, vmax].
N)r   r  r  r  r  )r   r  r   s     r   r  TwoSlopeNorm.autoscale_Noneb	  sq     	q!99$		DLL(@ADI99$tyy(@ADI %r    c           
         U R                  U5      u  p4U R                  U5        U R                  U R                  s=::  a  U R                  ::  d  O  [        S5      e[        R                  R                  [        R                  " X0R                  U R                  U R                  // SQ[        R                  * [        R                  S9[        R                  R                  U5      S9nU(       a  [        R                  " U5      S   nU$ )zB
Map value to the interval [0, 1]. The *clip* argument is unused.
z/vmin, vcenter, vmax must increase monotonicallyr   rz  r   leftrightr  r   )r  r  r  r  r  rh   r   r   masked_arrayinterpinfr  
atleast_1d)r   r%   r  r   r  s        r   r-  TwoSlopeNorm.__call__p	  s     !..u5F#yyDLL5DII5NOO##IIfyy$,,		B!rvv?v& $ ( ]]6*1-Fr    c                 r   U R                  5       (       d  [        S5      eU R                  U R                  5      u  u  p#U R                  U R                  5      u  u  pCU R                  U R
                  5      u  u  pS[        R                  " U/ SQX%U/[        R                  * [        R                  S9nU$ )Nr  r   r  )	r  rh   r  r  r  r  r   r  r  )r   r%   r  r  r  r  r   s          r   r  TwoSlopeNorm.inverse	  s    {{}}NOO''		2
''		2
**4<<8
5+t/D!#rvv7r    )r  r  r  rn  r   )r*   r+   r,   r-   r   r5  r  r  r  r-  r  r.   r/   r0   s   @r   r  r  .	  sJ    '0R   ^^ 
B$ r    r  c                     ^  \ rS rSrSU 4S jjrS rS r\S 5       r\R                  S 5       r\S 5       r
\
R                  S 5       r
\S	 5       r\R                  S
 5       r\S 5       r\R                  S 5       rSrU =r$ )CenteredNormi	  c                 <   > [         TU ]  SSUS9  Xl        X l        g)a|  
Normalize symmetrical data around a center (0 by default).

Unlike `TwoSlopeNorm`, `CenteredNorm` applies an equal rate of change
around the center.

Useful when mapping symmetrical data around a conceptual center
e.g., data that range from -2 to 4, with 0 as the midpoint, and
with equal rates of change around that midpoint.

Parameters
----------
vcenter : float, default: 0
    The data value that defines ``0.5`` in the normalization.
halfrange : float, optional
    The range of data values that defines a range of ``0.5`` in the
    normalization, so that *vcenter* - *halfrange* is ``0.0`` and
    *vcenter* + *halfrange* is ``1.0`` in the normalization.
    Defaults to the largest absolute difference to *vcenter* for
    the values in the dataset.
clip : bool, default: False
    Determines the behavior for mapping values outside the range
    ``[vmin, vmax]``.

    If clipping is off, values outside the range ``[vmin, vmax]`` are
    also transformed, resulting in values outside ``[0, 1]``.  This
    behavior is usually desirable, as colormaps can mark these *under*
    and *over* values with specific colors.

    If clipping is on, values below *vmin* are mapped to 0 and values
    above *vmax* are mapped to 1. Such values become indistinguishable
    from regular boundary values, which may cause misinterpretation of
    the data.

Examples
--------
This maps data values -2 to 0.25, 0 to 0.5, and 4 to 1.0
(assuming equal rates of change above and below 0.0):

    >>> import matplotlib.colors as mcolors
    >>> norm = mcolors.CenteredNorm(halfrange=4.0)
    >>> data = [-2., 0., 4.]
    >>> norm(data)
    array([0.25, 0.5 , 1.  ])
Nr  r  r  )r   r   r  	halfrange)r   r  r  r  r   s       r   r   CenteredNorm.__init__	  s$    \ 	dD9"r    c                     [         R                  " U5      n[        U R                  UR	                  5       -
  UR                  5       U R                  -
  5      U l        g)zI
Set *halfrange* to ``max(abs(A-vcenter))``, then set *vmin* and *vmax*.
N)r   r  r   r  r  r  r  s     r   r  CenteredNorm.autoscale	  sA     MM!T]]15572UUWT]]24r    c                     [         R                  " U5      nU R                  c$  UR                  (       a  U R	                  U5        ggg)zSet *vmin* and *vmax*.N)r   r  r  r  r  r  s     r   r  CenteredNorm.autoscale_None	  s4    MM!>>!affNN1 '-!r    c                     U R                   $ r   r  rL   s    r   r  CenteredNorm.vmin	  r  r    c                     [        U5      nXR                  :w  a.  Xl        SU R                  -  U-
  U l        U R	                  5         g g Nr   )r   r  r  r  r  r  s     r   r  r  	  =    !%(JJJ4<<%/DJMMO r    c                     U R                   $ r   r  rL   s    r   r  CenteredNorm.vmax	  r  r    c                     [        U5      nXR                  :w  a.  Xl        SU R                  -  U-
  U l        U R	                  5         g g r  )r   r  r  r  r  r  s     r   r  r  	  r  r    c                     U R                   $ r   r  rL   s    r   r  CenteredNorm.vcenter	  r  r    c                 r    XR                   :w  a(  Xl         U R                  U l        U R                  5         g g r   )r  r  r  )r   r  s     r   r  r  	  s*    mm##M!^^DNMMO	 $r    c                 p    U R                   b  U R                  c  g U R                  U R                   -
  S-  $ r  r  rL   s    r   r  CenteredNorm.halfrange	  s0    99		 1		DII%**r    c                     Uc  S U l         S U l        g U R                  [        U5      -
  U l         U R                  [        U5      -   U l        g r   )r  r  r  abs)r   r  s     r   r  r!  	  s>    DIDIs9~5DIs9~5DIr    )r  r  r  r  r  r  )r   NF)r*   r+   r,   r-   r   r  r  r5  r  r  r  r  r  r.   r/   r0   s   @r   r  r  	  s    1#f4   
[[    
[[    ^^  + +
 6 6r    r  initc          	      J   Uc  [         R                  " [        XS9$ [        U [         R                  5      (       a<  U R                  n[        U R                  R                  5       5      nU R                  n OS=p4Uc  SS jn[        XUU[        R                  " U5      5      $ )a  
Decorator for building a `.Normalize` subclass from a `~.scale.ScaleBase`
subclass.

After ::

    @make_norm_from_scale(scale_cls)
    class norm_cls(Normalize):
        ...

*norm_cls* is filled with methods so that normalization computations are
forwarded to *scale_cls* (i.e., *scale_cls* is the scale that would be used
for the colorbar of a mappable normalized with *norm_cls*).

If *init* is not passed, then the constructor signature of *norm_cls*
will be ``norm_cls(vmin=None, vmax=None, clip=False)``; these three
parameters will be forwarded to the base class (``Normalize.__init__``),
and a *scale_cls* object will be initialized with no arguments (other than
a dummy axis).

If the *scale_cls* constructor takes additional parameters, then *init*
should be passed to `make_norm_from_scale`.  It is a callable which is
*only* used for its signature.  First, this signature will become the
signature of *norm_cls*.  Second, the *norm_cls* constructor will bind the
parameters passed to it using this signature, extract the bound *vmin*,
*vmax*, and *clip* values, pass those to ``Normalize.__init__``, and
forward the remaining bound values (including any defaults defined by the
signature) to the *scale_cls* constructor.
r$  r7   c                     g r   r7   r  s      r   r%  "make_norm_from_scale.<locals>.init-
  s    Dr    r  )r  r  make_norm_from_scaler   r   r   keywordsr   r  _make_norm_from_scaleinspect	signature)	scale_clsbase_norm_clsr%  
scale_argsscale_kwargs_itemss        r   r)  r)  
  s    >   !5yLL)Y..//^^
"9#5#5#;#;#=>NN	*,,
|8 1w((.0 0r    c                    ^ ^^^^  " UUUU U4S jST5      nT[         L a)  T R                   S3Ul        T R                   S3Ul        O"TR                  Ul        TR                  Ul        TR                  Ul        TR                  Ul        U$ )a  
Helper for `make_norm_from_scale`.

This function is split out to enable caching (in particular so that
different unpickles reuse the same class).  In order to do so,

- ``functools.partial`` *scale_cls* is expanded into ``func, args, kwargs``
  to allow memoizing returned norms (partial instances always compare
  unequal, but we can check identity based on ``func, args, kwargs``;
- *init* is replaced by *init_signature*, as signatures are picklable,
  unlike to arbitrary lambdas.
c                     >^  \ rS rSrUUUUU4S jrU UUUU4S jr YR                  \R                  " S\R                  R                  5      / YR                  R                  5       QS9\l        S
S jrS rU 4S jrS	rU =r$ )#_make_norm_from_scale.<locals>.NormiF
  c                   > [        U 5      n U[        [        R                  " UR                  5      UR
                  5      L a  [        U4[        U 5      4$  [        TTTTT4[        U 5      4$ ! [        [        4 a     N)f = fr   )r  getattr	importlibimport_moduler+   r,   _create_empty_object_of_classvarsImportErrorr   _picklable_norm_constructor)r   rN  r/  bound_init_signaturer0  r.  r1  s     r   
__reduce__._make_norm_from_scale.<locals>.Norm.__reduce__G
  s    t*C')"9"9#.."I"%"2"24 49C64:NN4
 0
,>"$8:J     0 s   A	A0 0BBc                 z  > TR                   " U0 UD6nUR                  5         [        TU ]  " S0 S Vs0 s H  oDUR                  R                  U5      _M      snD6  [        R                  " T/TQ70 [        T	5      D6" SSS 0UR                  D6U l	        U R                  R                  5       U l        g s  snf )Nr  r   r7   )bindapply_defaultsr   r   	argumentsro   r  r  dictr  get_transform_trf)
r   r   r   bar   r   r=  r0  r.  r1  s
        r   r   ,_make_norm_from_scale.<locals>.Norm.__init__Z
  s    %**D;F;BG N3KL3Kabll&&q))3KLN#++D&D*./A*BD //!#/DK 113DI	 Ms   %B8r   )
parametersc                 f   U R                  U5      u  pU R                  b  U R                  c  U R                  U5        U R                  U R                  :  a  [	        S5      eU R                  U R                  :X  a  [
        R                  " US5      $ Uc  U R                  nU(       a+  [
        R                  " XR                  U R                  5      nU R                  R                  U5      R                  [
        R                  " U5      5      nU R                  R                  U R                  U R                  /5      u  pV[
        R                  " XV/5      R                  5       (       d  [	        S5      eXE-  nXFU-
  -  n[
        R                  R                  USS9nU(       a  US   $ U$ )N"vmin must be less or equal to vmaxr   Invalid vmin or vmaxFr0  )r  r  r  r  rh   r   	full_liker  rF  r  r   r   isfiniter   r   masked_invalid)r   r%   r  r  t_valuet_vmint_vmaxs          r   r-  ,_make_norm_from_scale.<locals>.Norm.__call__h
  sK   #11%8Eyy DII$5##E*yy499$ !EFFyyDII%||E1--|yyyy$))<ii))%088%IG!YY00$))TYY1GHNF;;/04466 !788G(Gee**7*?G!*71:77r    c                 L   U R                  5       (       d  [        S5      eU R                  U R                  :  a  [        S5      eU R                  R                  U R                  U R                  /5      u  p#[        R                  " X#/5      R                  5       (       d  [        S5      eU R                  U5      u  pXU-
  -  nXR-  nU R                  R                  5       R                  U5      R                  [        R                  " U5      5      nU(       a  US   $ U$ )NNot invertible until scaledrK  rL  r   )r  rh   r  r  rF  r  r   rN  r   r  r`  r   r   )r   r%   rQ  rR  r  rescaleds         r   r  +_make_norm_from_scale.<locals>.Norm.inverse}
  s    ;;== !>??yy499$ !EFF!YY00$))TYY1GHNF;;/04466 !788#11%8E0HHYYhji)gbhhuo.   )583e3r    c                    > [         R                  " [         R                  " U R                  R	                  U5      5      U5      nUR
                  S:X  a  [         R                  R                  n[        TU ]%  U5      $ )Nr   )
r   extractrN  rF  r  r  r   r   r   r  )r   r  in_trf_domainr   s      r   r  2_make_norm_from_scale.<locals>.Norm.autoscale_None
  sV    JJr{{4993F3Fq3I'JANM!!Q& "7)-88r    )r  rF  r   )r*   r+   r,   r-   r>  r   replacer,  	ParameterPOSITIONAL_OR_KEYWORDrI  values__signature__r-  r  r  r.   r/   )r   r/  r=  r0  r.  r1  s   @r   Normr4  F
  s}    	  	 &	4 	4 "6!=!=fg&7&7&M&MNJ7!,,335J7!= "8	8*	4"	9 	9r    ra  )r  r*   r,   r+   rs   )r.  r0  r1  r/  r=  ra  s   ````` r   r+  r+  4
  s    $M9 M9} M9^ 	!$--.d3(556d;%..)66#..DO ((DLKr    c                 $    U R                  U 5      $ r   )rJ  )rN  s    r   r9  r9  
  s    ;;sr    c                  $    [        [        U 6 5      $ r   )r9  r+  )r   s    r   r<  r<  
  s    ()>)EFFr    c                     g r   r7   )	functionsr  r  r  s       r   <lambda>rf  
  s    Tr    c                       \ rS rSrSrSrg)FuncNormi
  a  
Arbitrary normalization using functions for the forward and inverse.

Parameters
----------
functions : (callable, callable)
    two-tuple of the forward and inverse functions for the normalization.
    The forward function must be monotonic.

    Both functions must have the signature ::

       def forward(values: array-like) -> array-like

vmin, vmax : float or None
    If *vmin* and/or *vmax* is not given, they are initialized from the
    minimum and maximum value, respectively, of the first input
    processed; i.e., ``__call__(A)`` calls ``autoscale_None(A)``.

clip : bool, default: False
    Determines the behavior for mapping values outside the range
    ``[vmin, vmax]``.

    If clipping is off, values outside the range ``[vmin, vmax]`` are also
    transformed by the function, resulting in values outside ``[0, 1]``.
    This behavior is usually desirable, as colormaps can mark these *under*
    and *over* values with specific colors.

    If clipping is on, values below *vmin* are mapped to 0 and values above
    *vmax* are mapped to 1. Such values become indistinguishable from
    regular boundary values, which may cause misinterpretation of the data.
r7   N)r*   r+   r,   r-   rs   r.   r7   r    r   rh  rh  
  s    r    rh  r   )nonpositiveLogNormz8Normalize a given value to the 0-1 range on a log scale.
   )basec                    g r   r7   )	linthreshlinscaler  r  r  rl  s         r   rf  rf  
  s    r    c                   L    \ rS rSrSr\S 5       r\R                  S 5       rSrg)
SymLogNormi
  a  
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
----------
linthresh : float
    The range within which the plot is linear (to avoid having the plot
    go to infinity around zero).
linscale : float, default: 1
    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.
base : float, default: 10
c                 .    U R                   R                  $ r   r  rn  rL   s    r   rn  SymLogNorm.linthresh
  s    {{$$$r    c                 $    XR                   l        g r   rs  r  s     r   rn  rt  
  s     %r    r7   N)	r*   r+   r,   r-   rs   r5  rn  r  r.   r7   r    r   rq  rq  
  s5    
0 % % & &r    rq  c                     g r   r7   )linear_widthr  r  r  s       r   rf  rf  
  s    $r    c                   L    \ rS rSrSr\S 5       r\R                  S 5       rSrg)	AsinhNormi
  a1  
The inverse hyperbolic sine scale is approximately linear near
the origin, but becomes logarithmic for larger positive
or negative values. Unlike the `SymLogNorm`, the transition between
these linear and logarithmic regions is smooth, which may reduce
the risk of visual artifacts.

.. note::

   This API is provisional and may be revised in the future
   based on early user feedback.

Parameters
----------
linear_width : float, default: 1
    The effective width of the linear region, beyond which
    the transformation becomes asymptotically logarithmic
c                 .    U R                   R                  $ r   r  rw  rL   s    r   rw  AsinhNorm.linear_width  s    {{'''r    c                 $    XR                   l        g r   r{  r  s     r   rw  r|    s    #( r    r7   N)	r*   r+   r,   r-   rs   r5  rw  r  r.   r7   r    r   ry  ry  
  s5    & ( ( ) )r    ry  c                   @   ^  \ rS rSrSrSU 4S jjrSS jrS rSrU =r	$ )		PowerNormi  a  
Linearly map a given value to the 0-1 range and then apply
a power-law normalization over that range.

Parameters
----------
gamma : float
    Power law exponent.
vmin, vmax : float or None
    If *vmin* and/or *vmax* is not given, they are initialized from the
    minimum and maximum value, respectively, of the first input
    processed; i.e., ``__call__(A)`` calls ``autoscale_None(A)``.
clip : bool, default: False
    Determines the behavior for mapping values outside the range
    ``[vmin, vmax]``.

    If clipping is off, values above *vmax* are transformed by the power
    function, resulting in values above 1, and values below *vmin* are linearly
    transformed resulting in values below 0. This behavior is usually desirable, as
    colormaps can mark these *under* and *over* values with specific colors.

    If clipping is on, values below *vmin* are mapped to 0 and values above
    *vmax* are mapped to 1. Such values become indistinguishable from
    regular boundary values, which may cause misinterpretation of the data.

Notes
-----
The normalization formula is

.. math::

    \left ( \frac{x - v_{min}}{v_{max}  - v_{min}} \right )^{\gamma}

For input values below *vmin*, gamma is set to one.
c                 2   > [         TU ]  X#U5        Xl        g r   )r   r   r  )r   r  r  r  r  r   s        r   r   PowerNorm.__init__>  s    T*
r    c                    Uc  U R                   nU R                  U5      u  p4U R                  U5        U R                  nU R                  U R
                  pvXg:  a  [        S5      eXg:X  a  UR                  S5        OU(       aa  [        R                  R                  U5      n[        R                  R                  [        R                   " UR                  U5      Xg5      US9nUR                  n	X-  n	XU-
  -  n	[        R                  " XS:     U5      XS:  '   [        R                  R                  XR                  SS9nU(       a  US   nU$ )Nr  r   r  Fr  )r  r  r  r  r  r  rh   r  r   r   r  r   r  r  powerr   )
r   r%   r  r   r  r  r  r  r   r  s
             r   r-  PowerNorm.__call__B  s   <99D ..u5F#

YY		d;NOO\KKNuu}}V,RWWV]]4-@$%M*. % 0[[FNFd{#F!#&!*<e!DFA:UU[[kk[FFAYFr    c                    U R                  5       (       d  [        S5      eU R                  U5      u  p#U R                  nU R                  U R
                  peUR                  n[        R                  " XwS:     SU-  5      XwS:  '   XvU-
  -  nXu-  n[        R                  R                  XrR                  SS9nU(       a  US   nU$ )NrU  r   r   Fr  )r  rh   r  r  r  r  r  r   r  r   r   r   )r   r%   r   r  r  r  r  r  s           r   r  PowerNorm.inverse^  s    {{}}:;; ..u5

YY		dXXfaZ&8!e)Dz$;V++EBAYFr    )r  r  r   
r*   r+   r,   r-   rs   r   r-  r  r.   r/   r0   s   @r   r  r    s    "F8 r    r  c                   H   ^  \ rS rSrSrS	SS.U 4S jjjrS
S jrS rSrU =r	$ )BoundaryNormir  z
Generate a colormap index based on discrete intervals.

Unlike `Normalize` or `LogNorm`, `BoundaryNorm` maps values to integers
instead of to the interval 0-1.
neitherextendc                J  > U(       a  US:w  a  [        S5      e[        TU ]	  US   US   US9  [        R                  " U5      U l        [        U R
                  5      U l        U R                  S:  a  [        SU< 35      eX l        X@l	        SU l
        U R                  S	-
  U l        SU l        US
;   a  U =R                  S	-  sl        S	U l        US;   a  U =R                  S	-  sl        U R                  U R                  :  a  [        SU R                   SU S35      eg)a  
Parameters
----------
boundaries : array-like
    Monotonically increasing sequence of at least 2 bin edges:  data
    falling in the n-th bin will be mapped to the n-th color.

ncolors : int
    Number of colors in the colormap to be used.

clip : bool, optional
    If clip is ``True``, out of range values are mapped to 0 if they
    are below ``boundaries[0]`` or mapped to ``ncolors - 1`` if they
    are above ``boundaries[-1]``.

    If clip is ``False``, out of range values are mapped to -1 if
    they are below ``boundaries[0]`` or mapped to *ncolors* if they are
    above ``boundaries[-1]``. These are then converted to valid indices
    by `Colormap.__call__`.

extend : {'neither', 'both', 'min', 'max'}, default: 'neither'
    Extend the number of bins to include one or both of the
    regions beyond the boundaries.  For example, if ``extend``
    is 'min', then the color to which the region between the first
    pair of boundaries is mapped will be distinct from the first
    color in the colormap, and by default a
    `~matplotlib.colorbar.Colorbar` will be drawn with
    the triangle extension on the left or lower end.

Notes
-----
If there are fewer bins (including extensions) than colors, then the
color index is chosen by linearly interpolating the ``[0, nbins - 1]``
range onto the ``[0, ncolors - 1]`` range, effectively skipping some
colors in the middle of the colormap.
r  z+'clip=True' is not compatible with 'extend'r   r   r  r   zDYou must provide at least 2 boundaries (1 region) but you passed in Nr   r  bothr   r  z
There are z0 color bins including extensions, but ncolors = z1; ncolors must equal or exceed the number of bins)rh   r   r   r   r   
boundariesrZ   r  Ncmapr  r  
_n_regions_offset)r   r  ncolorsr  r  r   s        r   r   BoundaryNorm.__init__~  s   J Fi'JKKjm*R.tL**Z0T__%66A: ==GNL M M
&&1*_$OOq ODL_$OOq O??TZZ'z$//): ;D 'y ).. / / (r    c                    Uc  U R                   nU R                  U5      u  p4[        R                  R	                  U5      n[        R
                  " UR                  U R                  S-   5      5      nU(       a:  [        R                   " X0R                  U R                  US9  U R                  S-
  nOU R                  n[        R                  " X0R                  5      S-
  U R                  -   nU R                  U R                  :  aJ  U R                  S:X  a  U R                  S-
  S-  XwS:H  '   O"U R                  S-
  U R                  S-
  -  U-  nUR                  [        R                  5      nSXsU R                  :  '   XgX0R                  :  '   [        R                  R!                  XuS9nU(       a  [#        US   5      nU$ )zm
This method behaves similarly to `.Normalize.__call__`, except that it
returns integers or arrays of int16.
r   outr   r   r   r  )r  r  r   r   getmaskarrayr  r  r  r  r  digitizer  r  r  r@  int16r   r   )	r   r%   r  r  r  r   max_coliretr   s	            r   r-  BoundaryNorm.__call__  s[   
 <99D**51uu!!"%]]299TYY]34GGB		499"5jj1nGjjG {{2/!3dllB ::'!##'::>a"7QY 

Q4??Q+>?$F{{288$!$))^ 'R99_eekk$k*c!f+C
r    c                     [        S5      e)zt
Raises
------
ValueError
    BoundaryNorm is not invertible, so calling this method will always
    raise an error
zBoundaryNorm is not invertible)rh   r  s     r   r  BoundaryNorm.inverse  s     9::r    )r  r  r  r  r  r  r  r  r   r  r0   s   @r   r  r  r  s*    =/) =/ =/~(T; ;r    r  c                   (    \ rS rSrSrSS jrS rSrg)NoNormi  z}
Dummy replacement for `Normalize`, for the case where we want to use
indices directly in a `~matplotlib.cm.ScalarMappable`.
Nc                 z    [         R                  " U5      (       a  [         R                  R                  U5      $ U$ r   r   r   r   r   )r   r%   r  s      r   r-  NoNorm.__call__  )    ;;u55;;u%%r    c                 z    [         R                  " U5      (       a  [         R                  R                  U5      $ U$ r   r  r  s     r   r  NoNorm.inverse  r  r    r7   r   )r*   r+   r,   r-   rs   r-  r  r.   r7   r    r   r  r    s    
r    r  c                    [         R                  " U 5      n U R                  S   S:w  a  [        SU R                   S35      eU R                  n[         R                  " U S[         R
                  " U R                  [         R                  5      SS9n [         R                  " U 5      nU R                  S5      n[         R                  " US:  5      (       a  [        S	UR                  5        35      eU R                  5       S
:  a  [        SU R                  5        35      eUS
:  n[         R                  " U S5      n[         R                  " U5      nXT   X4   -  Xd'   US
:  nU S   U:H  U-  nXS4   XS4   -
  XW   -  X'S
4'   U S   U:H  U-  nSXS4   XS
4   -
  XW   -  -   X'S
4'   U S   U:H  U-  nSXS
4   XS4   -
  XW   -  -   X'S
4'   US   S-  S-  US'   XbS'   X2S'   UR                  U5      $ )a  
Convert an array of float RGB values (in the range [0, 1]) to HSV values.

Parameters
----------
arr : (..., 3) array-like
   All values must be in the range [0, 1]

Returns
-------
(..., 3) `~numpy.ndarray`
   Colors converted to HSV values in range [0, 1]
r   r   /Last dimension of input array must be 3; shape  was found.Fr   r   r   ndminr   zBInput array must be in the range [0, 1]. Found a maximum value of r   zBInput array must be in the range [0, 1]. Found a minimum value of .r   .r   g       @.r   g      @      @r   )r   r   r   rh   r   r  r   r  
zeros_liker   r   r  ptpr   )arrin_shaper  arr_maxiposdeltar*  idxs           r   
rgb_to_hsvr    s"    **S/C yy} ""%))K9 : 	: yyH
((%syy"**5C --
CggbkG	vvgk((/8
 	

 wwy1}((+	{4
 	

 Q;DFF3OE
eAkGM)AG19Dv;'!T
)CAv;!V,
:CQKv;'!T
)CFcq&k1UZ??CQKv;'!T
)CFcq&k1UZ??CQKv;$+CKKK;;x  r    c                    [         R                  " U 5      n U R                  S   S:w  a  [        SU R                   S35      eU R                  n[         R                  " U S[         R
                  " U R                  [         R                  5      SS9n U S   nU S	   nU S
   n[         R                  " U5      n[         R                  " U5      n[         R                  " U5      nUS-  R                  [        5      nUS-  U-
  n	USU-
  -  n
USX9-  -
  -  nUSUSU	-
  -  -
  -  nUS-  S:H  nXM   X]'   X   Xm'   X   X}'   US:H  nX   X]'   XM   Xm'   X   X}'   US:H  nX   X]'   XM   Xm'   X   X}'   US:H  nX   X]'   X   Xm'   XM   X}'   US:H  nX   X]'   X   Xm'   XM   X}'   US:H  nXM   X]'   X   Xm'   X   X}'   US:H  nXM   X]'   XM   Xm'   XM   X}'   [         R                  " XVU/SS9nUR                  U5      $ )z
Convert HSV values to RGB.

Parameters
----------
hsv : (..., 3) array-like
   All values assumed to be in range [0, 1]

Returns
-------
(..., 3) `~numpy.ndarray`
   Colors converted to RGB values in range [0, 1]
r   r   r  r  Fr   r  r  r  r  r  r      r   r   r   r   r   )r   r   r   rh   r   r  r   r  
empty_liker@  r   stackr   )hsvr  hr*  r   r  r  r  r
  r1  pqtr  rgbs                  r   
hsv_to_rgbr  C  s=    **S/C yy} ""%))K9 : 	: yyH
((%syy"**5C 	FAFAFA
aA
aA
aA	
SA	
SAA	S1WA	S15[A	S1a= !A
a%1*CVAFVAFVAF
q&CVAFVAFVAF
q&CVAFVAFVAF
q&CVAFVAFVAF
q&CVAFVAFVAF
q&CVAFVAFVAF
q&CVAFVAFVAF
((A!92
&C;;x  r    c                     Sn[        U R                  S   5       H  nXSU[        R                  4   S-  -  nM      [        R                  " U5      $ )Nr   r   .r   )ranger   r   rO  r{  )r  sum_sqr
  s      r   _vector_magnituder    sK     F399R=!c1bjj()Q.. "776?r    c                       \ rS rSrSr  SS jr\S 5       rSS jrSS jr	  SS jr
  SS	 jr  SS
 jrS rS rSrg)LightSourcei  a  
Create a light source coming from the specified azimuth and elevation.
Angles are in degrees, with the azimuth measured
clockwise from north and elevation up from the zero plane of the surface.

`shade` is used to produce "shaded" RGB values for a data array.
`shade_rgb` can be used to combine an RGB image with an elevation map.
`hillshade` produces an illumination map of a surface.
c                 L    Xl         X l        X0l        X@l        XPl        X`l        g)a  
Specify the azimuth (measured clockwise from south) and altitude
(measured up from the plane of the surface) of the light source
in degrees.

Parameters
----------
azdeg : float, default: 315 degrees (from the northwest)
    The azimuth (0-360, degrees clockwise from North) of the light
    source.
altdeg : float, default: 45 degrees
    The altitude (0-90, degrees up from horizontal) of the light
    source.
hsv_min_val : number, default: 0
    The minimum value ("v" in "hsv") that the *intensity* map can shift the
    output image to.
hsv_max_val : number, default: 1
    The maximum value ("v" in "hsv") that the *intensity* map can shift the
    output image to.
hsv_min_sat : number, default: 1
    The minimum saturation value that the *intensity* map can shift the output
    image to.
hsv_max_sat : number, default: 0
    The maximum saturation value that the *intensity* map can shift the output
    image to.

Notes
-----
For backwards compatibility, the parameters *hsv_min_val*,
*hsv_max_val*, *hsv_min_sat*, and *hsv_max_sat* may be supplied at
initialization as well.  However, these parameters will only be used if
"blend_mode='hsv'" is passed into `shade` or `shade_rgb`.
See the documentation for `blend_hsv` for more details.
N)azdegaltdeghsv_min_valhsv_max_valhsv_min_sathsv_max_sat)r   r  r  r  r  r  r  s          r   r   LightSource.__init__  s'    H 
&&&&r    c                    [         R                  " SU R                  -
  5      n[         R                  " U R                  5      n[         R                  " [         R
                  " U5      [         R
                  " U5      -  [         R                  " U5      [         R
                  " U5      -  [         R                  " U5      /5      $ )z3The unit vector direction towards the light source.Z   )r   radiansr  r  r   cossin)r   azalts      r   	directionLightSource.direction  s}    
 ZZTZZ(jj%xxFF2J$FF2J$FF3K
  	r    c                    U* n[         R                  " X!-  XC5      u  pg[         R                  " UR                  S-   5      R	                  [        U5      5      nU* US'   U* US'   SUS'   U[        U5      -  nU R                  X5      $ )a#  
Calculate the illumination intensity for a surface using the defined
azimuth and elevation for the light source.

This computes the normal vectors for the surface, and then passes them
on to `shade_normals`

Parameters
----------
elevation : 2D array-like
    The height values used to generate an illumination map
vert_exag : number, optional
    The amount to exaggerate the elevation values by when calculating
    illumination. This can be used either to correct for differences in
    units between the x-y coordinate system and the elevation
    coordinate system (e.g. decimal degrees vs. meters) or to
    exaggerate or de-emphasize topographic effects.
dx : number, optional
    The x-spacing (columns) of the input *elevation* grid.
dy : number, optional
    The y-spacing (rows) of the input *elevation* grid.
fraction : number, optional
    Increases or decreases the contrast of the hillshade.  Values
    greater than one will cause intermediate values to move closer to
    full illumination or shadow (and clipping any values that move
    beyond 0 or 1). Note that this is not visually or mathematically
    the same as vertical exaggeration.

Returns
-------
`~numpy.ndarray`
    A 2D array of illumination values between 0-1, where 0 is
    completely in shadow and 1 is completely illuminated.
)r   r  r  r   r  )r   gradientr  r   r<  r  r  shade_normals)	r   	elevation	vert_exagdxdyfractione_dye_dxnormals	            r   	hillshadeLightSource.hillshade  s    N S [[!6?
 )//D0166tIGvvv#F++!!&33r    c                     UR                  U R                  5      nUR                  5       UR                  5       pTX2-  nXT-
  S:  a  X4-  nX5U-
  -  n[        R
                  " USS5      nU$ )ar  
Calculate the illumination intensity for the normal vectors of a
surface using the defined azimuth and elevation for the light source.

Imagine an artificial sun placed at infinity in some azimuth and
elevation position illuminating our surface. The parts of the surface
that slope toward the sun should brighten while those sides facing away
should become darker.

Parameters
----------
fraction : number, optional
    Increases or decreases the contrast of the hillshade.  Values
    greater than one will cause intermediate values to move closer to
    full illumination or shadow (and clipping any values that move
    beyond 0 or 1). Note that this is not visually or mathematically
    the same as vertical exaggeration.

Returns
-------
`~numpy.ndarray`
    A 2D array of illumination values between 0-1, where 0 is
    completely in shadow and 1 is completely illuminated.
gư>r   r   )dotr  r  r   r   r  )r   normalsr  	intensityiminimaxs         r   r  LightSource.shade_normals  sm    4 KK/	 ]]_immod	
 K4
 I+&IGGIq!,	r    Nc           
          Uc  UR                  5       nUc  UR                  5       nUc	  [        XVS9nU" U" U5      5      nU R                  " U4XXxU	U
S.UD6nUSSS24   USSS24'   U$ )a{
  
Combine colormapped data values with an illumination intensity map
(a.k.a.  "hillshade") of the values.

Parameters
----------
data : 2D array-like
    The height values used to generate a shaded map.
cmap : `~matplotlib.colors.Colormap`
    The colormap used to color the *data* array. Note that this must be
    a `~matplotlib.colors.Colormap` instance.  For example, rather than
    passing in ``cmap='gist_earth'``, use
    ``cmap=plt.get_cmap('gist_earth')`` instead.
norm : `~matplotlib.colors.Normalize` instance, optional
    The normalization used to scale values before colormapping. If
    None, the input will be linearly scaled between its min and max.
blend_mode : {'hsv', 'overlay', 'soft'} or callable, optional
    The type of blending used to combine the colormapped data
    values with the illumination intensity.  Default is
    "overlay".  Note that for most topographic surfaces,
    "overlay" or "soft" appear more visually realistic. If a
    user-defined function is supplied, it is expected to
    combine an (M, N, 3) RGB array of floats (ranging 0 to 1) with
    an (M, N, 1) hillshade array (also 0 to 1).  (Call signature
    ``func(rgb, illum, **kwargs)``) Additional kwargs supplied
    to this function will be passed on to the *blend_mode*
    function.
vmin : float or None, optional
    The minimum value used in colormapping *data*. If *None* the
    minimum value in *data* is used. If *norm* is specified, then this
    argument will be ignored.
vmax : float or None, optional
    The maximum value used in colormapping *data*. If *None* the
    maximum value in *data* is used. If *norm* is specified, then this
    argument will be ignored.
vert_exag : number, optional
    The amount to exaggerate the elevation values by when calculating
    illumination. This can be used either to correct for differences in
    units between the x-y coordinate system and the elevation
    coordinate system (e.g. decimal degrees vs. meters) or to
    exaggerate or de-emphasize topography.
dx : number, optional
    The x-spacing (columns) of the input *elevation* grid.
dy : number, optional
    The y-spacing (rows) of the input *elevation* grid.
fraction : number, optional
    Increases or decreases the contrast of the hillshade.  Values
    greater than one will cause intermediate values to move closer to
    full illumination or shadow (and clipping any values that move
    beyond 0 or 1). Note that this is not visually or mathematically
    the same as vertical exaggeration.
**kwargs
    Additional kwargs are passed on to the *blend_mode* function.

Returns
-------
`~numpy.ndarray`
    An (M, N, 4) array of floats ranging between 0-1.
Nr  )r  
blend_moder  r  r  r  .r   )r  r   r  	shade_rgb)r   r  r  normr  r  r  r  r  r  r  r   rgb0rgb1s                 r   shadeLightSource.shadeE  s    z <88:D<88:D<$2DDJ~~d ;d(1R'/;39; S"1"WS"1"Wr    c                    U R                  X%XgU5      n	U	S[        R                  4   n	U R                  U R                  U R
                  S.n
XJ;   a  X   " X40 UD6nO
 U" X40 UD6n[        R                  R                  U	5      (       a3  U	R                  S   n[        S5       H  nUSU4   U   USU4   U'   M     U$ ! [         a  n[        SU
R                   35      UeSnAff = f)a  
Use this light source to adjust the colors of the *rgb* input array to
give the impression of a shaded relief map with the given *elevation*.

Parameters
----------
rgb : array-like
    An (M, N, 3) RGB array, assumed to be in the range of 0 to 1.
elevation : array-like
    An (M, N) array of the height values used to generate a shaded map.
fraction : number
    Increases or decreases the contrast of the hillshade.  Values
    greater than one will cause intermediate values to move closer to
    full illumination or shadow (and clipping any values that move
    beyond 0 or 1). Note that this is not visually or mathematically
    the same as vertical exaggeration.
blend_mode : {'hsv', 'overlay', 'soft'} or callable, optional
    The type of blending used to combine the colormapped data values
    with the illumination intensity.  For backwards compatibility, this
    defaults to "hsv". Note that for most topographic surfaces,
    "overlay" or "soft" appear more visually realistic. If a
    user-defined function is supplied, it is expected to combine an
    (M, N, 3) RGB array of floats (ranging 0 to 1) with an (M, N, 1)
    hillshade array (also 0 to 1).  (Call signature
    ``func(rgb, illum, **kwargs)``)
    Additional kwargs supplied to this function will be passed on to
    the *blend_mode* function.
vert_exag : number, optional
    The amount to exaggerate the elevation values by when calculating
    illumination. This can be used either to correct for differences in
    units between the x-y coordinate system and the elevation
    coordinate system (e.g. decimal degrees vs. meters) or to
    exaggerate or de-emphasize topography.
dx : number, optional
    The x-spacing (columns) of the input *elevation* grid.
dy : number, optional
    The y-spacing (rows) of the input *elevation* grid.
**kwargs
    Additional kwargs are passed on to the *blend_mode* function.

Returns
-------
`~numpy.ndarray`
    An (m, n, 3) array of floats ranging between 0-1.
.)r  softoverlayz("blend_mode" must be callable or one of Nr  r   )r  r   rO  	blend_hsvblend_soft_lightblend_overlayr   rh   keysr   r   r   r  )r   r  r  r  r  r  r  r  r   r  lookupblendr  r   r
  s                  r   r  LightSource.shade_rgb  s   ` NN9J	c2::o.	 ~~----
 &s@@E<"3<V< 55??9%%>>&)D1X&)#q&k$&7c1fd#    < !K$*KK="2 38;<<s   	C 
C)C$$C)c           
          Uc  U R                   nUc  U R                  nUc  U R                  nUc  U R                  nUS   nSU-  S-
  n[	        USS2SS2SS24   5      n[
        R                  " USS5      u  pn
[
        R                  " U	[
        R                  " U	5      S:  US:  -  SU-
  U	-  X#-  -   5        [
        R                  " U	[
        R                  " U	5      S:  US:  -  SU-   U	-  X&-  -
  5        [
        R                  " XS:  SU-
  U
-  X$-  -   5        [
        R                  " XS:  SU-   U
-  X%-  -
  5        [
        R                  " USS2SS2SS24   SSUSS2SS2SS24   S	9  [        U5      $ )
a  
Take the input data array, convert to HSV values in the given colormap,
then adjust those color values to give the impression of a shaded
relief map with a specified light source.  RGBA values are returned,
which can then be used to plot the shaded image with imshow.

The color of the resulting image will be darkened by moving the (s, v)
values (in HSV colorspace) toward (hsv_min_sat, hsv_min_val) in the
shaded regions, or lightened by sliding (s, v) toward (hsv_max_sat,
hsv_max_val) in regions that are illuminated.  The default extremes are
chose so that completely shaded points are nearly black (s = 1, v = 0)
and completely illuminated points are nearly white (s = 0, v = 1).

Parameters
----------
rgb : `~numpy.ndarray`
    An (M, N, 3) RGB array of floats ranging from 0 to 1 (color image).
intensity : `~numpy.ndarray`
    An (M, N, 1) array of floats ranging from 0 to 1 (grayscale image).
hsv_max_sat : number, optional
    The maximum saturation value that the *intensity* map can shift the output
    image to. If not provided, use the value provided upon initialization.
hsv_min_sat : number, optional
    The minimum saturation value that the *intensity* map can shift the output
    image to. If not provided, use the value provided upon initialization.
hsv_max_val : number, optional
    The maximum value ("v" in "hsv") that the *intensity* map can shift the
    output image to. If not provided, use the value provided upon
    initialization.
hsv_min_val : number, optional
    The minimum value ("v" in "hsv") that the *intensity* map can shift the
    output image to. If not provided, use the value provided upon
    initialization.

Returns
-------
`~numpy.ndarray`
    An (M, N, 3) RGB array representing the combined images.
Nr  r   r   r   r   r   g|=r  )r  r  r  r  r  r   moveaxisputmaskr#  r  r  )r   r  r  r  r  r  r  r  huesatr   s              r   r  LightSource.blend_hsv  s   T **K**K**K**K f%		MA%	 Q1Q3Y(CQ/# 	

3v-)a-@	MS(9+BB	D


3v-)a-@	MS(9+BB	D


3A	MS(9+BB	D


3A	MS(9+BB	D
Aq!"Hq!Q12X7 #r    c                 0    SU-  U-  SSU-  -
  US-  -  -   $ )a  
Combine an RGB image with an intensity map using "soft light" blending,
using the "pegtop" formula.

Parameters
----------
rgb : `~numpy.ndarray`
    An (M, N, 3) RGB array of floats ranging from 0 to 1 (color image).
intensity : `~numpy.ndarray`
    An (M, N, 1) array of floats ranging from 0 to 1 (grayscale image).

Returns
-------
`~numpy.ndarray`
    An (M, N, 3) RGB array representing the combined images.
r   r   r7   )r   r  r  s      r   r  LightSource.blend_soft_light%  s*    " 9}s"a!i-&736%AAAr    c                 h    SU-  U-  nSSSU-
  -  SU-
  -  -
  n[         R                  " US:*  X45      $ )aw  
Combine an RGB image with an intensity map using "overlay" blending.

Parameters
----------
rgb : `~numpy.ndarray`
    An (M, N, 3) RGB array of floats ranging from 0 to 1 (color image).
intensity : `~numpy.ndarray`
    An (M, N, 1) array of floats ranging from 0 to 1 (grayscale image).

Returns
-------
ndarray
    An (M, N, 3) RGB array representing the combined images.
r   r   rz  )r   where)r   r  r  lowhighs        r   r  LightSource.blend_overlay8  sC      )mc!1I&!c'22xxs
C..r    )r  r  r  r  r  r  )i;  -   r   r   r   r   )r   r   r   r   r   )Nr  NNr   r   r   r   )r   r  r   r   r   )NNNN)r*   r+   r,   r-   rs   r   r5  r  r  r  r  r  r  r  r  r.   r7   r    r   r  r    su     IJ,-)'V 
 
34j,\ GK;<JX AF()HT GK04HTB&/r    r  c                 R   [        SS5      [        SS5      [        SS5      [        SS5      S.n[        R                  " X2S9  X2   n[        U 5      S-
  nXTR                  -   UR
                  =(       d    S-
  n[        U5      U:w  a*  [        SU< S[        U 5       S	U S
[        U5       35      e[        X   US9nUS;   a  UR                  US   5        OUR                  S5        US;   a  UR                  US   5        OUR                  S5        X'l
        [        XS9nXx4$ )a+  
A helper routine to generate a cmap and a norm instance which
behave similar to contourf's levels and colors arguments.

Parameters
----------
levels : sequence of numbers
    The quantization levels used to construct the `BoundaryNorm`.
    Value ``v`` is quantized to level ``i`` if ``lev[i] <= v < lev[i+1]``.
colors : sequence of colors
    The fill color to use for each level. If *extend* is "neither" there
    must be ``n_level - 1`` colors. For an *extend* of "min" or "max" add
    one extra color, and for an *extend* of "both" add two colors.
extend : {'neither', 'min', 'max', 'both'}, optional
    The behaviour when a value falls out of range of the given levels.
    See `~.Axes.contourf` for details.

Returns
-------
cmap : `~matplotlib.colors.Colormap`
norm : `~matplotlib.colors.Normalize`
r   r   Nr   )r  r  r   r  r  zWith extend == z and z levels, expected z colors, but got )r  r  r   r  )r  )slicer	   r  rZ   startstoprh   r  rf  rl  r'  r  )	levelsr   r  	slice_mapcolor_slicen_data_colors
n_expectedr  r  s	            r   from_levels_and_colorsr  M  s*   0 aQ~Q|D>	I 	y0#KK!OM!2!22k6F6F6K!LJ
6{j fZuS[M :"|#4S[MCD 	D &-?D vay!v fRj!f!6D:r    r   r  r  r  )r   NNF)r   NNF)r  )ars   r  collections.abcr   r   r   r  r7  r,  r  r  numbersr   r   PILr   PIL.PngImagePluginr   
matplotlibr   numpyr   r	   r
   r   r   r   _color_datar   r   r   r   rD  r   r6   rL  r   r\  r  r  r8   r:   rK   r   compiler   r   r   r   r   r   ri   r   r   r   r  cnameshexColorPatternrgb2hex	hex2colorr  colorConverterr  r  r  r  r   r7  r  r^  r  r  r  r)  r   r+  r9  r<  	FuncScalerh  r  LogScalerj  r*   r,   SymmetricalLogScalerq  
AsinhScalery  r  r  r  r  r  r  r  r  )r   r   s   00r   <module>r.     s  'R  4 4    	   	  &   6 6 N ND       $   %0%6%6%8)%8TQ"aK 6662A5%8) *    $    '   %3%9%9%;)%;TQ"aK 6662A5%;) *    $ !12  
g.G g.T )*  

>*9

2M 5&,^[|iX
G2 
**34
	
0 
0  !_"D@ @F
`h `F\X \~zC zCzs sl/] /d2] 2jd? d?N\9 \~s69 s6l.0 .0b i iXG 	OO	ACy CD enn&9;;DF*3 3 7'L 	

& &	&D 		FH)	 )H):U	 Up};9 };@Y  >!BO!dk/ k/\6o)
)s   L?
*L?

M
M
