B
    AW[@                 @   sR  d Z ddlmZ ddlZddlZddlmZmZ eej	dkZ
eej	dkZdd	d
dddddgZddddddddddddddddd d!gZered"d#d$d%d&d'd(d)d*g	 d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=gZdRdCdZdDd	 ZdEd
 ZdSdFdZdTdGdZdUdHdZdVdIdZG dJdK dKeZG dLdM dMeZG dNdO dOeZdWdQdZdS )XzGControl plot style and scaling using the matplotlib rcParams interface.    )LooseVersionN   )palettes_orig_rc_paramsz1.5.0z2.0setreset_defaults
reset_orig
axes_style	set_styleplotting_contextset_contextset_palettezaxes.facecolorzaxes.edgecolorz	axes.gridzaxes.axisbelowzaxes.labelcolorzfigure.facecolorz
grid.colorzgrid.linestylez
text.colorzxtick.colorzytick.colorzxtick.directionzytick.directionzlines.solid_capstylezpatch.edgecolorz
image.cmapzfont.familyzfont.sans-serifzpatch.force_edgecolorzxtick.bottomz	xtick.topz
ytick.leftzytick.rightzaxes.spines.leftzaxes.spines.bottomzaxes.spines.rightzaxes.spines.topz	font.sizezaxes.labelsizezaxes.titlesizezxtick.labelsizezytick.labelsizezlegend.fontsizezaxes.linewidthzgrid.linewidthzlines.linewidthzlines.markersizezpatch.linewidthzxtick.major.widthzytick.major.widthzxtick.minor.widthzytick.minor.widthzxtick.major.sizezytick.major.sizezxtick.minor.sizezytick.minor.sizenotebookdarkgriddeep
sans-serifTc             C   s>   t | | t|d|id t||d |dk	r:tj| dS )a  Set aesthetic parameters in one step.

    Each set of parameters can be set directly or temporarily, see the
    referenced functions below for more information.

    Parameters
    ----------
    context : string or dict
        Plotting context parameters, see :func:`plotting_context`
    style : string or dict
        Axes style parameters, see :func:`axes_style`
    palette : string or sequence
        Color palette, see :func:`color_palette`
    font : string
        Font family, see matplotlib font manager.
    font_scale : float, optional
        Separate scaling factor to independently scale the size of the
        font elements.
    color_codes : bool
        If ``True`` and ``palette`` is a seaborn palette, remap the shorthand
        color codes (e.g. "b", "g", "r", etc.) to the colors from this palette.
    rc : dict or None
        Dictionary of rc parameter mappings to override the above.

    zfont.family)rc)color_codesN)r   r
   r   mplrcParamsupdate)contextstylepaletteZfont
font_scaler   r    r   ,lib/python3.7/site-packages/seaborn/rcmod.pyr   \   s
    
c               C   s   t jt j dS )z*Restore all RC params to default settings.N)r   r   r   ZrcParamsDefaultr   r   r   r   r   ~   s    c               C   s   t jt dS )z@Restore all RC params to original settings (respects custom rc).N)r   r   r   r   r   r   r   r   r      s    c             C   s  | dkrdd t D }n8t| tr,| }n&dddddg}| |krTtd	d
| d}d}d|dd||dd|dgdddddgddddddd}d| kr|ddi n|ddi | dr|dddddddd nJ| dkr|d||ddddd n$| dkr&|d||ddddd | dkrB|ddd n|ddd d d | D }|dk	rd!d | D }|| t|}|S )"a  Return a parameter dict for the aesthetic style of the plots.

    This affects things like the color of the axes, whether a grid is
    enabled by default, and other aesthetic elements.

    This function returns an object that can be used in a ``with`` statement
    to temporarily change the style parameters.

    Parameters
    ----------
    style : dict, None, or one of {darkgrid, whitegrid, dark, white, ticks}
        A dictionary of parameters or the name of a preconfigured set.
    rc : dict, optional
        Parameter mappings to override the values in the preset seaborn
        style dictionaries. This only updates parameters that are
        considered part of the style definition.

    Examples
    --------
    >>> st = axes_style("whitegrid")

    >>> set_style("ticks", {"xtick.major.size": 8, "ytick.major.size": 8})

    >>> import matplotlib.pyplot as plt
    >>> with axes_style("white"):
    ...     f, ax = plt.subplots()
    ...     ax.plot(x, y)               # doctest: +SKIP

    See Also
    --------
    set_style : set the matplotlib parameters for a seaborn theme
    plotting_context : return a parameter dict to to scale plot elements
    color_palette : define the color palette for a plot

    Nc             S   s   i | ]}t j| |qS r   )r   r   ).0kr   r   r   
<dictcomp>   s    zaxes_style.<locals>.<dictcomp>whiteZdarkZ	whitegridr   tickszstyle must be one of %sz, z.15z.8outT-z
sans-serifZArialzDejaVu SanszLiberation SanszBitstream Vera SansroundwZrocketF)zfigure.facecolorzaxes.labelcolorzxtick.directionzytick.directionzxtick.colorzytick.colorzaxes.axisbelowzgrid.linestylez
text.colorzfont.familyzfont.sans-serifzlines.solid_capstylezpatch.edgecolorzpatch.force_edgecolorz
image.cmapz	xtick.topzytick.rightZgridz	axes.gridz#EAEAF2)zaxes.facecolorzaxes.edgecolorz
grid.colorzaxes.spines.leftzaxes.spines.bottomzaxes.spines.rightzaxes.spines.top)r    r!   )zxtick.bottomz
ytick.leftc             S   s   i | ]\}}|t kr||qS r   )_style_keys)r   r   vr   r   r   r     s    c             S   s   i | ]\}}|t kr||qS r   )r&   )r   r   r'   r   r   r   r   "  s    )	r&   
isinstancedict
ValueErrorjoinr   
startswithitems
_AxesStyle)r   r   Z
style_dictZstylesZ	dark_grayZ
light_graystyle_objectr   r   r   r	      s    $









c             C   s   t | |}tj| dS )a  Set the aesthetic style of the plots.

    This affects things like the color of the axes, whether a grid is
    enabled by default, and other aesthetic elements.

    Parameters
    ----------
    style : dict, None, or one of {darkgrid, whitegrid, dark, white, ticks}
        A dictionary of parameters or the name of a preconfigured set.
    rc : dict, optional
        Parameter mappings to override the values in the preset seaborn
        style dictionaries. This only updates parameters that are
        considered part of the style definition.

    Examples
    --------
    >>> set_style("whitegrid")

    >>> set_style("ticks", {"xtick.major.size": 8, "ytick.major.size": 8})

    See Also
    --------
    axes_style : return a dict of parameters or use in a ``with`` statement
                 to temporarily set the style.
    set_context : set parameters to scale plot elements
    set_palette : set the default color palette for figures

    N)r	   r   r   r   )r   r   r/   r   r   r   r
   +  s    
c                s  | dkrdd t D  nt| tr(|  nddddg}| |krNtdd	| d
d
d
ddddddddddddddddd}tddddd|  fdd| D  ddddddg} fdd|D } | |dk	rdd | D } | t }|S )aB  Return a parameter dict to scale elements of the figure.

    This affects things like the size of the labels, lines, and other
    elements of the plot, but not the overall style. The base context
    is "notebook", and the other contexts are "paper", "talk", and "poster",
    which are version of the notebook parameters scaled by .8, 1.3, and 1.6,
    respectively.

    This function returns an object that can be used in a ``with`` statement
    to temporarily change the context parameters.

    Parameters
    ----------
    context : dict, None, or one of {paper, notebook, talk, poster}
        A dictionary of parameters or the name of a preconfigured set.
    font_scale : float, optional
        Separate scaling factor to independently scale the size of the
        font elements.
    rc : dict, optional
        Parameter mappings to override the values in the preset seaborn
        context dictionaries. This only updates parameters that are
        considered part of the context definition.

    Examples
    --------
    >>> c = plotting_context("poster")

    >>> c = plotting_context("notebook", font_scale=1.5)

    >>> c = plotting_context("talk", rc={"lines.linewidth": 2})

    >>> import matplotlib.pyplot as plt
    >>> with plotting_context("paper"):
    ...     f, ax = plt.subplots()
    ...     ax.plot(x, y)                 # doctest: +SKIP

    See Also
    --------
    set_context : set the matplotlib parameters to scale plot elements
    axes_style : return a dict of parameters defining a figure style
    color_palette : define the color palette for a plot

    Nc             S   s   i | ]}t j| |qS r   )r   r   )r   r   r   r   r   r   y  s    z$plotting_context.<locals>.<dictcomp>paperr   talkposterzcontext must be in %sz,       g      ?r   g      ?      )z	font.sizezaxes.labelsizezaxes.titlesizezxtick.labelsizezytick.labelsizezlegend.fontsizezaxes.linewidthzgrid.linewidthzlines.linewidthzlines.markersizezpatch.linewidthzxtick.major.widthzytick.major.widthzxtick.minor.widthzytick.minor.widthzxtick.major.sizezytick.major.sizezxtick.minor.sizezytick.minor.sizeg?   )r0   r   r1   r2   c                s   i | ]\}}|  |qS r   r   )r   r   r'   )scalingr   r   r     s    zaxes.labelsizezaxes.titlesizezlegend.fontsizezxtick.labelsizezytick.labelsizez	font.sizec                s   i | ]} |  |qS r   r   )r   r   )context_dictr   r   r   r     s    c             S   s   i | ]\}}|t kr||qS r   )_context_keys)r   r   r'   r   r   r   r     s    )r:   r(   r)   r*   r+   r-   r   _PlottingContext)r   r   r   ZcontextsZbase_contextZ	font_keysZ	font_dictcontext_objectr   )r9   r   r8   r   r   L  sJ    ,



c             C   s   t | ||}tj| dS )a&  Set the plotting context parameters.

    This affects things like the size of the labels, lines, and other
    elements of the plot, but not the overall style. The base context
    is "notebook", and the other contexts are "paper", "talk", and "poster",
    which are version of the notebook parameters scaled by .8, 1.3, and 1.6,
    respectively.

    Parameters
    ----------
    context : dict, None, or one of {paper, notebook, talk, poster}
        A dictionary of parameters or the name of a preconfigured set.
    font_scale : float, optional
        Separate scaling factor to independently scale the size of the
        font elements.
    rc : dict, optional
        Parameter mappings to override the values in the preset seaborn
        context dictionaries. This only updates parameters that are
        considered part of the context definition.

    Examples
    --------
    >>> set_context("paper")

    >>> set_context("talk", font_scale=1.4)

    >>> set_context("talk", rc={"lines.linewidth": 2})

    See Also
    --------
    plotting_context : return a dictionary of rc parameters, or use in
                       a ``with`` statement to temporarily set the context.
    set_style : set the default parameters for figure style
    set_palette : set the default color palette for figures

    N)r   r   r   r   )r   r   r   r<   r   r   r   r     s    %c               @   s$   e Zd Zdd Zdd Zdd ZdS )_RCAestheticsc                s*   t j  fdd| jD | _| |  d S )Nc                s   i | ]} | |qS r   r   )r   r   )r   r   r   r     s    z+_RCAesthetics.__enter__.<locals>.<dictcomp>)r   r   _keys_orig_set)selfr   )r   r   	__enter__  s    z_RCAesthetics.__enter__c             C   s   |  | j d S )N)r@   r?   )rA   exc_type	exc_valueZexc_tbr   r   r   __exit__  s    z_RCAesthetics.__exit__c                s   t   fdd}|S )Nc           	      s     | |S Q R X d S )Nr   )argskwargs)funcrA   r   r   wrapper  s    z'_RCAesthetics.__call__.<locals>.wrapper)	functoolswraps)rA   rH   rI   r   )rH   rA   r   __call__  s    z_RCAesthetics.__call__N)__name__
__module____qualname__rB   rE   rL   r   r   r   r   r=     s   r=   c               @   s   e Zd ZdZeZeeZdS )r.   z1Light wrapper on a dict to set style temporarily.N)	rM   rN   rO   __doc__r&   r>   staticmethodr
   r@   r   r   r   r   r.     s   r.   c               @   s   e Zd ZdZeZeeZdS )r;   z3Light wrapper on a dict to set context temporarily.N)	rM   rN   rO   rP   r:   r>   rQ   r   r@   r   r   r   r   r;     s   r;   Fc             C   s|   t | ||}tr4ddlm} |d|}|tjd< nt|tjd< |d tjd< |rxyt |  W n tk
rv   Y nX dS )a1  Set the matplotlib color cycle using a seaborn palette.

    Parameters
    ----------
    palette : seaborn color paltte | matplotlib colormap | hls | husl
        Palette definition. Should be something that :func:`color_palette`
        can process.
    n_colors : int
        Number of colors in the cycle. The default number of colors will depend
        on the format of ``palette``, see the :func:`color_palette`
        documentation for more information.
    desat : float
        Proportion to desaturate each color by.
    color_codes : bool
        If ``True`` and ``palette`` is a seaborn palette, remap the shorthand
        color codes (e.g. "b", "g", "r", etc.) to the colors from this palette.

    Examples
    --------
    >>> set_palette("Reds")

    >>> set_palette("Set1", 8, .75)

    See Also
    --------
    color_palette : build a color palette or set the color cycle temporarily
                    in a ``with`` statement.
    set_context : set parameters to scale plot elements
    set_style : set the default parameters for figure style

    r   )cyclerZcolorzaxes.prop_cyclezaxes.color_cyclezpatch.facecolorN)	r   Zcolor_palette
mpl_ge_150rR   r   r   listZset_color_codesr*   )r   Zn_colorsZdesatr   ZcolorsrR   Zcylr   r   r   r     s     
)r   r   r   r   r   TN)NN)NN)Nr   N)Nr   N)NNF)rP   Zdistutils.versionr   rJ   Z
matplotlibr    r   r   __version__rS   Zmpl_ge_2__all__r&   extendr:   r   r   r   r	   r
   r   r   r)   r=   r.   r;   r   r   r   r   r   <module>   s    
!
 $
!
i
)