3
hm|                 @   s.  d dl Z d dlmZ d dlZd dlZddlmZ ddl	m
Z
mZ ddlmZmZ ddd	d
ddddddddgZeddddddddddg
ddddddgdddd d!d"d#d$d%d&g
ddd d!d%d&gd'd(d)d*d+d,d-d.d/d0g
d'd)d*d+d/d0gd1d2d3d4d5d6d7d8d9d:g
d1d3d4d5d9d:gd;d<d=d>d?d@dAdBdCdDg
d;d=d>d?dCdDgdEdFdGdHdIdJdKdLdMdNg
dEdGdHdIdMdNgdOZdPdQdQdQdRdSdTdSdTdRdSdSdUZej ZejdVdW ej D  eej ZG dXdY dYeZdzd[dZd{d`dZd|dbd	Zd}dcd
Zddde Zd~dgdZ ddhdZ!ddldZ"ddmdZ#dnd Z$dod Z%ddudZ&dvdw Z'ddydZ(dS )    N)cycle   )husl)
desaturateget_color_cycle)xkcd_rgbcrayonscolor_palettehls_palettehusl_palettempl_palettedark_palettelight_palettediverging_paletteblend_palettexkcd_palettecrayon_palettecubehelix_paletteset_color_codesz#4C72B0z#DD8452z#55A868z#C44E52z#8172B3z#937860z#DA8BC3z#8C8C8Cz#CCB974z#64B5CDz#4878D0z#EE854Az#6ACC64z#D65F5Fz#956CB4z#8C613Cz#DC7EC0z#797979z#D5BB67z#82C6E2z#A1C9F4z#FFB482z#8DE5A1z#FF9F9Bz#D0BBFFz#DEBB9Bz#FAB0E4z#CFCFCFz#FFFEA3z#B9F2F0z#023EFFz#FF7C00z#1AC938z#E8000Bz#8B2BE2z#9F4800z#F14CC1z#A3A3A3z#FFC400z#00D7FFz#001C7Fz#B1400Dz#12711Cz#8C0800z#591E71z#592F0Dz#A23582z#3C3C3Cz#B8850Az#006374z#0173B2z#DE8F05z#029E73z#D55E00z#CC78BCz#CA9161z#FBAFE4z#949494z#ECE133z#56B4E9)deepZdeep6ZmutedZmuted6ZpastelZpastel6ZbrightZbright6darkZdark6Z
colorblindZcolorblind6
      	         )Ztab10Ztab20Ztab20bZtab20cZSet1ZSet2ZSet3ZAccentZPairedZPastel1ZPastel2ZDark2c             C   s   i | ]\}}t ||qS  )len).0kvr   r   3/tmp/pip-build-riy7u7_k/seaborn/seaborn/palettes.py
<dictcomp>8   s    r"   c               @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )_ColorPalettez?Set the color palette in a with statement, otherwise be a list.c             C   s    ddl m} t | _||  | S )zOpen the context.r   )set_palette)rcmodr$   r	   _orig_palette)selfr$   r   r   r!   	__enter__>   s    z_ColorPalette.__enter__c             G   s   ddl m} || j dS )zClose the context.r   )r$   N)r%   r$   r&   )r'   argsr$   r   r   r!   __exit__E   s    z_ColorPalette.__exit__c             C   s   dd | D }t |S )z<Return a color palette with hex codes instead of RGB values.c             S   s   g | ]}t jj|qS r   )mplcolorsZrgb2hex)r   rgbr   r   r!   
<listcomp>L   s    z(_ColorPalette.as_hex.<locals>.<listcomp>)r#   )r'   hexr   r   r!   as_hexJ   s    z_ColorPalette.as_hexc             C   sn   d}t | }d||  d| d}x>t| j D ].\}}|d||  d| d| d| d	7 }q0W |d	7 }|S )
z6Rich display of the color palette in an HTML frontend.7   z<svg  width="z
" height="z">z	<rect x="z" y="0" width="z" style="fill:z*;stroke-width:2;stroke:rgb(255,255,255)"/>z</svg>)r   	enumerater0   )r'   snhtmlicr   r   r!   _repr_html_O   s    (z_ColorPalette._repr_html_N)__name__
__module____qualname____doc__r(   r*   r0   r8   r   r   r   r!   r#   <   s
   r#   Fc       
         sd  | dkr"t  } |dkrt| }nt| tsD| } |dkr@t| }n|dkrXtj| d}| tkrlt|  } nr| dkrt||d} nZ| dkrt||d} nB| j	 dkrt
dn*| jdrt| \}}t|f||d	|i} n| jd
r,| jd\}}|jd}|r|dd }t||||d} n| jdrt| jd\}}|jd}|rb|dd }t||||d} nj| jdr| jd\}}	|	jd}	t|	||d} n6yt| ||d} W n" t
k
r   t
d|  Y nX  dk	r fdd| D } |s`t| fddt|D } yttjjj| } t| } W n$ t
k
r^   t
d|  Y nX | S )a  Return a list of colors or continuous colormap defining a palette.

    Possible ``palette`` values include:
        - Name of a seaborn palette (deep, muted, bright, pastel, dark, colorblind)
        - Name of matplotlib colormap
        - 'husl' or 'hls'
        - 'ch:<cubehelix arguments>'
        - 'light:<color>', 'dark:<color>', 'blend:<color>,<color>',
        - A sequence of colors in any format matplotlib accepts

    Calling this function with ``palette=None`` will return the current
    matplotlib color cycle.

    This function can also be used in a ``with`` statement to temporarily
    set the color cycle for a plot or set of plots.

    See the :ref:`tutorial <palette_tutorial>` for more information.

    Parameters
    ----------
    palette : None, string, or sequence, optional
        Name of palette or None to return current palette. If a sequence, input
        colors are used but possibly cycled and desaturated.
    n_colors : int, optional
        Number of colors in the palette. If ``None``, the default will depend
        on how ``palette`` is specified. Named palettes default to 6 colors,
        but grabbing the current palette or passing in a list of colors will
        not change the number of colors unless this is specified. Asking for
        more colors than exist in the palette will cause it to cycle. Ignored
        when ``as_cmap`` is True.
    desat : float, optional
        Proportion to desaturate each color by.
    as_cmap : bool
        If True, return a :class:`matplotlib.colors.Colormap`.

    Returns
    -------
    list of RGB tuples or :class:`matplotlib.colors.Colormap`

    See Also
    --------
    set_palette : Set the default color cycle for all plots.
    set_color_codes : Reassign color codes like ``"b"``, ``"g"``, etc. to
                      colors from one of the seaborn palettes.

    Examples
    --------

    .. include:: ../docstrings/color_palette.rst

    N   hls)as_cmapr   ZjetzNo.zch:r?   zlight::_r   )reverser?   zdark:zblend:,z%s is not a valid palette namec                s   g | ]}t | qS r   )r   )r   r7   )desatr   r!   r.      s    z!color_palette.<locals>.<listcomp>c                s   g | ]}t  qS r   )next)r   _)	pal_cycler   r!   r.      s    z!Could not generate a palette for rI   )r   r   
isinstancestrQUAL_PALETTE_SIZESgetSEABORN_PALETTESr
   r   lower
ValueError
startswith_parse_cubehelix_argsr   splitendswithr   r   r   r   r   rangemapr+   r,   colorConverterto_rgbr#   )
paletten_colorsrE   r?   r)   kwargsrG   colorrC   r,   r   )rE   rH   r!   r	   ]   sh    4





r=   {Gz?333333??c                sv   |rd} t jddt| d dd }||7 }|d; }||jt8 } fdd|D }|rjtjj|dS t|S dS )	a  Get a set of evenly spaced colors in HLS hue space.

    h, l, and s should be between 0 and 1

    Parameters
    ----------

    n_colors : int
        number of colors in the palette
    h : float
        first hue
    l : float
        lightness
    s : float
        saturation

    Returns
    -------
    list of RGB tuples or :class:`matplotlib.colors.Colormap`

    See Also
    --------
    husl_palette : Make a palette using evenly spaced hues in the HUSL system.

    Examples
    --------

    Create a palette of 10 colors with the default parameters:

    .. plot::
        :context: close-figs

        >>> import seaborn as sns; sns.set_theme()
        >>> sns.palplot(sns.hls_palette(10))

    Create a palette of 10 colors that begins at a different hue value:

    .. plot::
        :context: close-figs

        >>> sns.palplot(sns.hls_palette(10, h=.5))

    Create a palette of 10 colors that are darker than the default:

    .. plot::
        :context: close-figs

        >>> sns.palplot(sns.hls_palette(10, l=.4))

    Create a palette of 10 colors that are less saturated than the default:

    .. plot::
        :context: close-figs

        >>> sns.palplot(sns.hls_palette(10, s=.4))

       r   r   Nc                s   g | ]}t j| qS r   )colorsys
hls_to_rgb)r   h_i)lr3   r   r!   r.   %  s    zhls_palette.<locals>.<listcomp>r>   )nplinspaceintZastyper+   r,   ListedColormapr#   )rZ   hrd   r3   r?   huesrY   r   )rd   r3   r!   r
      s    :?c                s   |rd} t jddt| d dd
 }||7 }|d; }|d9 }d9  d9   fdd|D }|rttjj|d	S t|S dS )a  Get a set of evenly spaced colors in HUSL hue space.

    h, s, and l should be between 0 and 1

    Parameters
    ----------

    n_colors : int
        number of colors in the palette
    h : float
        first hue
    s : float
        saturation
    l : float
        lightness

    Returns
    -------
    list of RGB tuples or :class:`matplotlib.colors.Colormap`

    See Also
    --------
    hls_palette : Make a palette using evently spaced circular hues in the
                  HSL system.

    Examples
    --------

    Create a palette of 10 colors with the default parameters:

    .. plot::
        :context: close-figs

        >>> import seaborn as sns; sns.set_theme()
        >>> sns.palplot(sns.husl_palette(10))

    Create a palette of 10 colors that begins at a different hue value:

    .. plot::
        :context: close-figs

        >>> sns.palplot(sns.husl_palette(10, h=.5))

    Create a palette of 10 colors that are darker than the default:

    .. plot::
        :context: close-figs

        >>> sns.palplot(sns.husl_palette(10, l=.4))

    Create a palette of 10 colors that are less saturated than the default:

    .. plot::
        :context: close-figs

        >>> sns.palplot(sns.husl_palette(10, s=.4))

    r`   r   r   Nig  c   c                s   g | ]}t | fd dqS )r   )input)_color_to_rgb)r   rc   )rd   r3   r   r!   r.   o  s    z husl_palette.<locals>.<listcomp>Zhslre   )rf   rg   rh   r+   r,   ri   r#   )rZ   rj   r3   rd   r?   rk   rY   r   )rd   r3   r!   r   ,  s    ;c       	      C   s   | j drh| dd }|j dr2d}|dd }nd}t|ddg }|rX|ddd }t||dd	}ntjj| }| tkrtjd
dt|  d| }ntjd
dt	|d dd }t
tt||ddddf }|r|S t|S dS )a  Return discrete colors from a matplotlib palette.

    Note that this handles the qualitative colorbrewer palettes
    properly, although if you ask for more colors than a particular
    qualitative palette can provide you will get fewer than you are
    expecting. In contrast, asking for qualitative color brewer palettes
    using :func:`color_palette` will return the expected number of colors,
    but they will cycle.

    If you are using the IPython notebook, you can also use the function
    :func:`choose_colorbrewer_palette` to interactively select palettes.

    Parameters
    ----------
    name : string
        Name of the palette. This should be a named matplotlib colormap.
    n_colors : int
        Number of discrete colors in the palette.

    Returns
    -------
    list of RGB tuples or :class:`matplotlib.colors.Colormap`

    Examples
    --------

    Create a qualitative colorbrewer palette with 8 colors:

    .. plot::
        :context: close-figs

        >>> import seaborn as sns; sns.set_theme()
        >>> sns.palplot(sns.mpl_palette("Set2", 8))

    Create a sequential colorbrewer palette:

    .. plot::
        :context: close-figs

        >>> sns.palplot(sns.mpl_palette("Blues"))

    Create a diverging palette:

    .. plot::
        :context: close-figs

        >>> sns.palplot(sns.mpl_palette("seismic", 8))

    Create a "dark" sequential palette:

    .. plot::
        :context: close-figs

        >>> sns.palplot(sns.mpl_palette("GnBu_d"))

    Z_dNrB   rA   TFz#333333r   )r?   r      rI   rI   re   re   )rT   r	   r   r+   cmZget_cmapMPL_QUAL_PALSrf   rg   rh   listrV   tupler#   )	namerZ   r?   Zsub_namerC   palcmapZbinsrY   r   r   r!   r   v  s$    9

"c             C   sV   |dkrt j|  } n6|dkr:tj|  } ttj| dd} n|dkrJt|  } tj	j
| S )z+Add some more flexibility to color choices.r>   r   r   r   Zxkcd)ra   rb   r   Zhusl_to_rgbrt   rf   Zclipr   r+   r,   rX   )r\   rn   r   r   r!   ro     s    
ro   r-   c             C   sZ   t | |}tj| \}}}d| d }	}
t ||	|
fdd}|rF||gn||g}t|||S )a  Make a sequential palette that blends from dark to ``color``.

    This kind of palette is good for data that range between relatively
    uninteresting low values and interesting high values.

    The ``color`` parameter can be specified in a number of ways, including
    all options for defining a color in matplotlib and several additional
    color spaces that are handled by seaborn. You can also use the database
    of named colors from the XKCD color survey.

    If you are using the IPython notebook, you can also choose this palette
    interactively with the :func:`choose_dark_palette` function.

    Parameters
    ----------
    color : base color for high values
        hex, rgb-tuple, or html color name
    n_colors : int, optional
        number of colors in the palette
    reverse : bool, optional
        if True, reverse the direction of the blend
    as_cmap : bool, optional
        If True, return a :class:`matplotlib.colors.Colormap`.
    input : {'rgb', 'hls', 'husl', xkcd'}
        Color space to interpret the input color. The first three options
        apply to tuple inputs and the latter applies to string inputs.

    Returns
    -------
    list of RGB tuples or :class:`matplotlib.colors.Colormap`

    See Also
    --------
    light_palette : Create a sequential palette with bright low values.
    diverging_palette : Create a diverging palette with two colors.

    Examples
    --------

    Generate a palette from an HTML color:

    .. plot::
        :context: close-figs

        >>> import seaborn as sns; sns.set_theme()
        >>> sns.palplot(sns.dark_palette("purple"))

    Generate a palette that decreases in lightness:

    .. plot::
        :context: close-figs

        >>> sns.palplot(sns.dark_palette("seagreen", reverse=True))

    Generate a palette from an HUSL-space seed:

    .. plot::
        :context: close-figs

        >>> sns.palplot(sns.dark_palette((260, 75, 60), input="husl"))

    Generate a colormap object:

    .. plot::
        :context: close-figs

        >>> from numpy import arange
        >>> x = arange(25).reshape(5, 5)
        >>> cmap = sns.dark_palette("#2ecc71", as_cmap=True)
        >>> ax = sns.heatmap(x, cmap=cmap)

    g333333?   r   )rn   )ro   r   rgb_to_huslr   )r\   rZ   rC   r?   rn   r-   rj   r3   rd   gray_sgray_lgrayr,   r   r   r!   r     s    I
c             C   sZ   t | |}tj| \}}}d| d }	}
t ||	|
fdd}|rF||gn||g}t|||S )a  Make a sequential palette that blends from light to ``color``.

    This kind of palette is good for data that range between relatively
    uninteresting low values and interesting high values.

    The ``color`` parameter can be specified in a number of ways, including
    all options for defining a color in matplotlib and several additional
    color spaces that are handled by seaborn. You can also use the database
    of named colors from the XKCD color survey.

    If you are using the IPython notebook, you can also choose this palette
    interactively with the :func:`choose_light_palette` function.

    Parameters
    ----------
    color : base color for high values
        hex code, html color name, or tuple in ``input`` space.
    n_colors : int, optional
        number of colors in the palette
    reverse : bool, optional
        if True, reverse the direction of the blend
    as_cmap : bool, optional
        If True, return a :class:`matplotlib.colors.Colormap`.
    input : {'rgb', 'hls', 'husl', xkcd'}
        Color space to interpret the input color. The first three options
        apply to tuple inputs and the latter applies to string inputs.

    Returns
    -------
    list of RGB tuples or :class:`matplotlib.colors.Colormap`

    See Also
    --------
    dark_palette : Create a sequential palette with dark low values.
    diverging_palette : Create a diverging palette with two colors.

    Examples
    --------

    Generate a palette from an HTML color:

    .. plot::
        :context: close-figs

        >>> import seaborn as sns; sns.set_theme()
        >>> sns.palplot(sns.light_palette("purple"))

    Generate a palette that increases in lightness:

    .. plot::
        :context: close-figs

        >>> sns.palplot(sns.light_palette("seagreen", reverse=True))

    Generate a palette from an HUSL-space seed:

    .. plot::
        :context: close-figs

        >>> sns.palplot(sns.light_palette((260, 75, 60), input="husl"))

    Generate a colormap object:

    .. plot::
        :context: close-figs

        >>> from numpy import arange
        >>> x = arange(25).reshape(5, 5)
        >>> cmap = sns.light_palette("#2ecc71", as_cmap=True)
        >>> ax = sns.heatmap(x, cmap=cmap)

    g333333?_   r   )rn   )ro   r   ry   r   )r\   rZ   rC   r?   rn   r-   rj   r3   rd   rz   r{   r|   r,   r   r   r!   r   '  s    I
K   2   lightc             C   s   t ttd| }td|d  }	|| ||f|	ddd}
||||f|	dd}t dgdgd
| }|| }ttj|
||g||d}|S )a  Make a diverging palette between two HUSL colors.

    If you are using the IPython notebook, you can also choose this palette
    interactively with the :func:`choose_diverging_palette` function.

    Parameters
    ----------
    h_neg, h_pos : float in [0, 359]
        Anchor hues for negative and positive extents of the map.
    s : float in [0, 100], optional
        Anchor saturation for both extents of the map.
    l : float in [0, 100], optional
        Anchor lightness for both extents of the map.
    sep : int, optional
        Size of the intermediate region.
    n : int, optional
        Number of colors in the palette (if not returning a cmap)
    center : {"light", "dark"}, optional
        Whether the center of the palette is light or dark
    as_cmap : bool, optional
        If True, return a :class:`matplotlib.colors.Colormap`.

    Returns
    -------
    list of RGB tuples or :class:`matplotlib.colors.Colormap`

    See Also
    --------
    dark_palette : Create a sequential palette with dark values.
    light_palette : Create a sequential palette with light values.

    Examples
    --------

    Generate a blue-white-red palette:

    .. plot::
        :context: close-figs

        >>> import seaborn as sns; sns.set_theme()
        >>> sns.palplot(sns.diverging_palette(240, 10, n=9))

    Generate a brighter green-white-purple palette:

    .. plot::
        :context: close-figs

        >>> sns.palplot(sns.diverging_palette(150, 275, s=80, l=55, n=9))

    Generate a blue-black-red palette:

    .. plot::
        :context: close-figs

        >>> sns.palplot(sns.diverging_palette(250, 15, s=75, l=40,
        ...                                   n=9, center="dark"))

    Generate a colormap object:

    .. plot::
        :context: close-figs

        >>> from numpy import arange
        >>> x = arange(25).reshape(5, 5)
        >>> cmap = sns.diverging_palette(220, 20, as_cmap=True)
        >>> ax = sns.heatmap(x, cmap=cmap)

    )r   r      rB   Tr   )rC   rn   )rn   ffffff?/$?)r   r   )r?   )r   r   r   )r   r   r   )dictr   r   rh   r   rf   Zconcatenate)Zh_negZh_posr3   rd   sepr4   centerr?   ZpalfuncZn_halfnegposZmidpointZmidrv   r   r   r!   r   x  s    Fc                sb    fdd| D } d}t jjj|| }|s^|tjddt|ddddf }ttt	|}|S )a  Make a palette that blends between a list of colors.

    Parameters
    ----------
    colors : sequence of colors in various formats interpreted by ``input``
        hex code, html color name, or tuple in ``input`` space.
    n_colors : int, optional
        Number of colors in the palette.
    as_cmap : bool, optional
        If True, return a :class:`matplotlib.colors.Colormap`.

    Returns
    -------
    list of RGB tuples or :class:`matplotlib.colors.Colormap`

    c                s   g | ]}t | qS r   )ro   )r   r\   )rn   r   r!   r.     s    z!blend_palette.<locals>.<listcomp>Zblendr   r   Nrp   )
r+   r,   LinearSegmentedColormap	from_listrf   rg   rh   r#   rV   rt   )r,   rZ   r?   rn   ru   rv   Z	rgb_arrayr   )rn   r!   r     s    &c             C   s   dd | D }t |t|S )a^  Make a palette with color names from the xkcd color survey.

    See xkcd for the full list of colors: https://xkcd.com/color/rgb/

    This is just a simple wrapper around the ``seaborn.xkcd_rgb`` dictionary.

    Parameters
    ----------
    colors : list of strings
        List of keys in the ``seaborn.xkcd_rgb`` dictionary.

    Returns
    -------
    palette : seaborn color palette
        Returns the list of colors as RGB tuples in an object that behaves like
        other seaborn color palettes.

    See Also
    --------
    crayon_palette : Make a palette with Crayola crayon colors.

    c             S   s   g | ]}t | qS r   )r   )r   ru   r   r   r!   r.     s    z xkcd_palette.<locals>.<listcomp>)r	   r   )r,   rY   r   r   r!   r     s    c             C   s   dd | D }t |t|S )a  Make a palette with color names from Crayola crayons.

    Colors are taken from here:
    https://en.wikipedia.org/wiki/List_of_Crayola_crayon_colors

    This is just a simple wrapper around the ``seaborn.crayons`` dictionary.

    Parameters
    ----------
    colors : list of strings
        List of keys in the ``seaborn.crayons`` dictionary.

    Returns
    -------
    palette : seaborn color palette
        Returns the list of colors as rgb tuples in an object that behaves like
        other seaborn color palettes.

    See Also
    --------
    xkcd_palette : Make a palette with named colors from the XKCD color survey.

    c             S   s   g | ]}t | qS r   )r   )r   ru   r   r   r!   r.     s    z"crayon_palette.<locals>.<listcomp>)r	   r   )r,   rY   r   r   r!   r     s    皙?      ?皙?333333?333333?c	                s    fdd}	|	dd|	dd|	ddd	}
t jjd
|
}tj||t| }||ddddf j }|r~|ddd }|rtj||d}|r|ddd }||}t jj|d}|S t|S dS )a  Make a sequential palette from the cubehelix system.

    This produces a colormap with linearly-decreasing (or increasing)
    brightness. That means that information will be preserved if printed to
    black and white or viewed by someone who is colorblind.  "cubehelix" is
    also available as a matplotlib-based palette, but this function gives the
    user more control over the look of the palette and has a different set of
    defaults.

    In addition to using this function, it is also possible to generate a
    cubehelix palette generally in seaborn using a string-shorthand; see the
    example below.

    Parameters
    ----------
    n_colors : int
        Number of colors in the palette.
    start : float, 0 <= start <= 3
        The hue at the start of the helix.
    rot : float
        Rotations around the hue wheel over the range of the palette.
    gamma : float 0 <= gamma
        Gamma factor to emphasize darker (gamma < 1) or lighter (gamma > 1)
        colors.
    hue : float, 0 <= hue <= 1
        Saturation of the colors.
    dark : float 0 <= dark <= 1
        Intensity of the darkest color in the palette.
    light : float 0 <= light <= 1
        Intensity of the lightest color in the palette.
    reverse : bool
        If True, the palette will go from dark to light.
    as_cmap : bool
        If True, return a :class:`matplotlib.colors.Colormap`.

    Returns
    -------
    list of RGB tuples or :class:`matplotlib.colors.Colormap`

    See Also
    --------
    choose_cubehelix_palette : Launch an interactive widget to select cubehelix
                               palette parameters.
    dark_palette : Create a sequential palette with dark low values.
    light_palette : Create a sequential palette with bright low values.

    References
    ----------
    Green, D. A. (2011). "A colour scheme for the display of astronomical
    intensity images". Bulletin of the Astromical Society of India, Vol. 39,
    p. 289-295.

    Examples
    --------

    Generate the default palette:

    .. plot::
        :context: close-figs

        >>> import seaborn as sns; sns.set_theme()
        >>> sns.palplot(sns.cubehelix_palette())

    Rotate backwards from the same starting location:

    .. plot::
        :context: close-figs

        >>> sns.palplot(sns.cubehelix_palette(rot=-.4))

    Use a different starting point and shorter rotation:

    .. plot::
        :context: close-figs

        >>> sns.palplot(sns.cubehelix_palette(start=2.8, rot=.1))

    Reverse the direction of the lightness ramp:

    .. plot::
        :context: close-figs

        >>> sns.palplot(sns.cubehelix_palette(reverse=True))

    Generate a colormap object:

    .. plot::
        :context: close-figs

        >>> from numpy import arange
        >>> x = arange(25).reshape(5, 5)
        >>> cmap = sns.cubehelix_palette(as_cmap=True)
        >>> ax = sns.heatmap(x, cmap=cmap)

    Use the full lightness range:

    .. plot::
        :context: close-figs

        >>> cmap = sns.cubehelix_palette(dark=0, light=1, as_cmap=True)
        >>> ax = sns.heatmap(x, cmap=cmap)

    Use through the :func:`color_palette` interface:

    .. plot::
        :context: close-figs

        >>> sns.palplot(sns.color_palette("ch:2,r=.2,l=.6"))

    c                s    fdd}|S )Nc                sZ   |   }| d|  d }dt j d |    }||t j| t j|    S )Nr   rB   rp   )rf   picossin)xZxgaphi)gammahuep0p1rotstartr   r!   r\     s    z<cubehelix_palette.<locals>.get_color_function.<locals>.colorr   )r   r   r\   )r   r   r   r   )r   r   r!   get_color_function  s    z-cubehelix_palette.<locals>.get_color_functiongK?g9?gۅ:?gRQ?g)?g        )ZredZgreenZblueZ	cubehelixNrp   r   r`   Zseaborn_cubehelixgKÿgۅ:ҿgRQre   re   )	r+   r,   r   rf   rg   rh   tolistri   r#   )rZ   r   r   r   r   r   r   rC   r?   r   Zcdictrw   r   rv   Zx_256Zpal_256r   )r   r   r   r   r!   r     s"    pc                s   | j dr| dd } | jdr2d}| dd } nd}| sFg d|ifS | jd	}d
d |D }dd |D }dd |D }tddddddd  fdd|j D }|rd|d< ||fS )z3Turn stringified cubehelix params into args/kwargs.zch:rp   NrA   TrB   FrC   rD   c             S   s"   g | ]}d |krt |jdqS )= )floatstrip)r   r   r   r   r!   r.     s    z)_parse_cubehelix_args.<locals>.<listcomp>c             S   s   g | ]}d |kr|j d qS )r   )rS   )r   r   r   r   r!   r.     s    c             S   s&   i | ]\}}t |jd |jd qS )r   )r   r   )r   r   r    r   r   r!   r"     s    z)_parse_cubehelix_args.<locals>.<dictcomp>r   r   r   r   r   r   )r3   rgrj   rd   dc                s   i | ]\}}| j ||qS r   )rM   )r   r   r    )	kwarg_mapr   r!   r"     s    rI   )rQ   rT   rS   r   items)ZargstrrC   Zall_argsr)   r[   r   )r   r!   rR     s&    


rR   r   c          	   C   s   | dkrdddddddg}nTt | ts4d}t|n<| tkr^| jdsN| d } t|  dg }nd	j| }t|x@td
|D ]2\}}tj	j
j|}|tj	j
j	|< |tj	j
j|< q|W dS )aH  Change how matplotlib color shorthands are interpreted.

    Calling this will change how shorthand codes like "b" or "g"
    are interpreted by matplotlib in subsequent plots.

    Parameters
    ----------
    palette : {deep, muted, pastel, dark, bright, colorblind}
        Named seaborn palette to use as the source of colors.

    See Also
    --------
    set : Color codes can be set through the high-level seaborn style
          manager.
    set_palette : Color codes can also be set through the function that
                  sets the matplotlib color cycle.

    Examples
    --------

    Map matplotlib color codes to the default seaborn palette.

    .. plot::
        :context: close-figs

        >>> import matplotlib.pyplot as plt
        >>> import seaborn as sns; sns.set_theme()
        >>> sns.set_color_codes()
        >>> _ = plt.plot([0, 1], color="r")

    Use a different seaborn palette.

    .. plot::
        :context: close-figs

        >>> sns.set_color_codes("dark")
        >>> _ = plt.plot([0, 1], color="g")
        >>> _ = plt.plot([0, 2], color="m")

    reset              ?      ?      ?z0set_color_codes requires a named seaborn palette6皙?z#Cannot set colors with palette '{}'ZbgrmyckN)r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )r   r   r   )rJ   rK   	TypeErrorrN   rT   formatrP   zipr+   r,   rW   rX   cache)rY   r,   errcoder\   r-   r   r   r!   r     s     )



)NNNF)r=   r]   r^   r_   F)r=   r]   rl   r_   F)r=   F)r=   FFr-   )r=   FFr-   )r~   r   r   r=   r   F)r=   Fr-   )	r=   r   r   r   r   r   r   FF)r   ))ra   	itertoolsr   Znumpyrf   Z
matplotlibr+   Zexternalr   utilsr   r   r,   r   r   __all__r   rN   rr   copyrL   updater   rs   keysZQUAL_PALETTESr#   r	   r
   r   r   ro   r   r   r   r   r   r   r   rR   r   r   r   r   r!   <module>   sz   





!
 	
G
J
S
Q
Q 
O
 
 #