U
    Evf&                     @   st  d Z ddlZddlZddlZddlmZ ddlZddlZejdkrPddl	m
Z nddlZddlZddlmZmZmZmZ eeZdddd	d
gZeje dZeje dgZdZdddddddddddddddhZdd dD ZdZe d e!d!j"e#ee$j%d"d#d Z&ej'd/d%dZ(d&d' Z)d(d) Z*d*d+ Z+G d,d- d-e,Z-e*eZ.e- Z/g Z0d.d
 Z1e1  dS )0aD  
Core functions and attributes for the matplotlib style library:

``use``
    Select style sheet to override the current matplotlib settings.
``context``
    Context manager to use a style sheet temporarily.
``available``
    List available style sheets.
``library``
    A dictionary of style names and matplotlib settings.
    N)Path)   
   )_api
_docstring_rc_params_in_filercParamsDefaultusecontext	availablelibraryreload_libraryZstylelibZmplstyleinteractivebackendzwebagg.portzwebagg.addresszwebagg.port_retrieszwebagg.open_in_browserZbackend_fallbackZtoolbartimezonezfigure.max_open_warningzfigure.raise_windowzsavefig.directoryztk.window_focuszdocstring.hardcopyz
date.epochc                 C   s   i | ]}|| d dqS )seabornzseaborn-v0_8)replace).0s r   9/tmp/pip-unpacked-wheel-7vhvci0g/matplotlib/style/core.py
<dictcomp>/   s    r   )r   zseaborn-brightzseaborn-colorblindzseaborn-darkzseaborn-darkgridzseaborn-dark-palettezseaborn-deepzseaborn-mutedzseaborn-notebookzseaborn-paperzseaborn-pastelzseaborn-posterzseaborn-talkzseaborn-tickszseaborn-whitezseaborn-whitegridzThe seaborn styles shipped by Matplotlib are deprecated since %(since)s, as they no longer correspond to the styles shipped by seaborn. However, they will remain available as 'seaborn-v0_8-<style>'. Alternatively, directly use the seaborn API instead.
z- {})keyc                 C   s  t | ttfst| dr | g}n| }ddd}|D ]z} t | tr|| | } | tkrntjdtd t|  } | dkrt	  dd t
D } W 5 Q R X n|| tkrt|  } njd	| kr| d	\}}}z$t|| d	t  }t|} W n* tttfk
r } zW 5 d
}~X Y nX t | ttfrhzt| } W n4 tk
rf } zt| d|W 5 d
}~X Y nX i }	| D ]0}
|
tkrtd|
d n| |
 |	|
< qptj|	 q2d
S )a  
    Use Matplotlib style settings from a style specification.

    The style name of 'default' is reserved for reverting back to
    the default style settings.

    .. note::

       This updates the `.rcParams` with the settings from the style.
       `.rcParams` not defined in the style are kept.

    Parameters
    ----------
    style : str, dict, Path or list

        A style specification. Valid options are:

        str
            - One of the style names in `.style.available` (a builtin style or
              a style installed in the user library path).

            - A dotted name of the form "package.style_name"; in that case,
              "package" should be an importable Python package name, e.g. at
              ``/path/to/package/__init__.py``; the loaded style file is
              ``/path/to/package/style_name.mplstyle``.  (Style files in
              subpackages are likewise supported.)

            - The path or URL to a style file, which gets loaded by
              `.rc_params_from_file`.

        dict
            A mapping of key/value pairs for `matplotlib.rcParams`.

        Path
            The path to a style file, which gets loaded by
            `.rc_params_from_file`.

        list
            A list of style specifiers (str, Path or dict), which are applied
            from first to last in the list.

    Notes
    -----
    The following `.rcParams` are not related to style and will be ignored if
    found in a style specification:

    %s
    keysdefaultZclassic)Zmpl20Zmpl153.6messagec                 S   s   i | ]}|t kr|t| qS r   )STYLE_BLACKLISTr   )r   kr   r   r   r      s     zuse.<locals>.<dictcomp>.Nz is not a valid package style, path of style file, URL of style file, or library style name (library styles are listed in `style.available`)zStyle includes a parameter, z9, that is not related to style.  Ignoring this parameter.)
isinstancestrr   hasattrget_DEPRECATED_SEABORN_STYLESr   warn_deprecated_DEPRECATED_SEABORN_MSGZ'suppress_matplotlib_deprecation_warningr   r   
rpartitionimportlib_resourcesfilesSTYLE_EXTENSIONr   ModuleNotFoundErrorOSError	TypeErrorIOErrorr   Zwarn_externalmplZrcParamsupdate)stylestylesZstyle_aliaspkg_namepathexcerrfilteredr    r   r   r   r	   K   sR    4






Fc              	   c   s2   t    |rt   t|  dV  W 5 Q R X dS )a  
    Context manager for using style settings temporarily.

    Parameters
    ----------
    style : str, dict, Path or list
        A style specification. Valid options are:

        str
            - One of the style names in `.style.available` (a builtin style or
              a style installed in the user library path).

            - A dotted name of the form "package.style_name"; in that case,
              "package" should be an importable Python package name, e.g. at
              ``/path/to/package/__init__.py``; the loaded style file is
              ``/path/to/package/style_name.mplstyle``.  (Style files in
              subpackages are likewise supported.)

            - The path or URL to a style file, which gets loaded by
              `.rc_params_from_file`.
        dict
            A mapping of key/value pairs for `matplotlib.rcParams`.

        Path
            The path to a style file, which gets loaded by
            `.rc_params_from_file`.

        list
            A list of style specifiers (str, Path or dict), which are applied
            from first to last in the list.

    after_reset : bool
        If True, apply style after resetting settings to their defaults;
        otherwise, apply style on top of the current settings.
    N)r1   Z
rc_contextZ
rcdefaultsr	   )r3   Zafter_resetr   r   r   r
      s
    %
c                 C   s*   t tjjtD ]}t|}t| | q| S )z0Update style library with user-defined rc files.)maposr8   
expanduserUSER_LIBRARY_PATHSread_style_directoryupdate_nested_dict)r   Zstylelib_pathr4   r   r   r   update_user_library   s    rB   c              
   C   sd   t  }t| dt D ]D}tjdd}t|||j< W 5 Q R X |D ]}t	d||j
 qHq|S )z3Return dictionary of styles defined in *style_dir*.z*.T)recordz	In %s: %s)dictr   globr,   warningscatch_warningsr   stem_logwarningr   )Z	style_dirr4   r8   Zwarnswr   r   r   r@      s    r@   c                 C   s(   |  D ]\}}| |i | q| S )a  
    Update nested dict (only level of nesting) with new values.

    Unlike `dict.update`, this assumes that the values of the parent dict are
    dicts (or dict-like), so you shouldn't replace the nested dict if it
    already exists. Instead you should update the sub-dict.
    )items
setdefaultr2   )Z	main_dictZnew_dictr7   Zrc_dictr   r   r   rA      s    	rA   c                   @   s   e Zd Zdd ZdS )_StyleLibraryc                 C   s*   |t krtjdtd t | }t| |S )Nr   r   )r&   r   r'   r(   rD   __getitem__)selfr   r   r   r   rO     s    z_StyleLibrary.__getitem__N)__name__
__module____qualname__rO   r   r   r   r   rN     s   rN   c                   C   s.   t   t tt tt  tdd< dS )zReload the style library.N)r   clearr2   rB   _base_librarysortedr   r   r   r   r   r   r     s    )F)2__doc__
contextlibloggingr=   pathlibr   sysrF   version_infoimportlib.resources	resourcesr*   Z
matplotlibr1   r   r   r   r   	getLoggerrQ   rI   __all__r8   joinZget_data_pathZBASE_LIBRARY_PATHZget_configdirr?   r,   r   r&   r(   ZSubstitutionr<   formatrV   r#   lowerr	   contextmanagerr
   rB   r@   rA   rD   rN   rU   r   r   r   r   r   r   r   <module>   sh   

          
i+