Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Backport PR #24265 on branch v3.6.x (Restore (and warn on) seaborn styles in style.library) #24270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 41 additions & 28 deletions lib/matplotlib/style/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,32 @@ class __getattr__:
'toolbar', 'timezone', 'figure.max_open_warning',
'figure.raise_window', 'savefig.directory', 'tk.window_focus',
'docstring.hardcopy', 'date.epoch'}
_DEPRECATED_SEABORN_STYLES = {
s: s.replace("seaborn", "seaborn-v0_8")
for s in [
"seaborn",
"seaborn-bright",
"seaborn-colorblind",
"seaborn-dark",
"seaborn-darkgrid",
"seaborn-dark-palette",
"seaborn-deep",
"seaborn-muted",
"seaborn-notebook",
"seaborn-paper",
"seaborn-pastel",
"seaborn-poster",
"seaborn-talk",
"seaborn-ticks",
"seaborn-white",
"seaborn-whitegrid",
]
}
_DEPRECATED_SEABORN_MSG = (
"The 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.")


def _remove_blacklisted_style_params(d, warn=True):
Expand Down Expand Up @@ -113,31 +139,9 @@ def use(style):
def fix_style(s):
if isinstance(s, str):
s = style_alias.get(s, s)
if s in [
"seaborn",
"seaborn-bright",
"seaborn-colorblind",
"seaborn-dark",
"seaborn-darkgrid",
"seaborn-dark-palette",
"seaborn-deep",
"seaborn-muted",
"seaborn-notebook",
"seaborn-paper",
"seaborn-pastel",
"seaborn-poster",
"seaborn-talk",
"seaborn-ticks",
"seaborn-white",
"seaborn-whitegrid",
]:
_api.warn_deprecated(
"3.6", message="The 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.")
s = s.replace("seaborn", "seaborn-v0_8")
if s in _DEPRECATED_SEABORN_STYLES:
_api.warn_deprecated("3.6", message=_DEPRECATED_SEABORN_MSG)
s = _DEPRECATED_SEABORN_STYLES[s]
return s

for style in map(fix_style, styles):
Expand Down Expand Up @@ -244,17 +248,26 @@ def update_nested_dict(main_dict, new_dict):
return main_dict


class _StyleLibrary(dict):
def __getitem__(self, key):
if key in _DEPRECATED_SEABORN_STYLES:
_api.warn_deprecated("3.6", message=_DEPRECATED_SEABORN_MSG)
key = _DEPRECATED_SEABORN_STYLES[key]

return dict.__getitem__(self, key)


# Load style library
# ==================
_base_library = read_style_directory(BASE_LIBRARY_PATH)
library = None
library = _StyleLibrary()
available = []


def reload_library():
"""Reload the style library."""
global library
library = update_user_library(_base_library)
library.clear()
library.update(update_user_library(_base_library))
available[:] = sorted(library.keys())


Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/tests/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ def test_deprecated_seaborn_styles():
with pytest.warns(mpl._api.MatplotlibDeprecationWarning):
mpl.style.use("seaborn-bright")
assert mpl.rcParams == seaborn_bright
with pytest.warns(mpl._api.MatplotlibDeprecationWarning):
mpl.style.library["seaborn-bright"]


def test_up_to_date_blacklist():
Expand Down