Skip to content

Rename outdated seaborn styles. #22317

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 1 commit into from
Jan 26, 2022
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
8 changes: 8 additions & 0 deletions doc/api/next_api_changes/deprecations/22317-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
seaborn styles renamed
~~~~~~~~~~~~~~~~~~~~~~
Matplotlib currently ships many style files inspired from the seaborn
library ("seaborn", "seaborn-bright", "seaborn-colorblind", etc.) but they
have gone out of sync with the library itself since the release of seaborn
0.9. To prevent confusion, the style files have been renamed "seaborn0.8",
"seaborn0.8-bright", "seaborn0.8-colorblind", etc. Users are encouraged to
directly use seaborn to access the up-to-date styles.
38 changes: 33 additions & 5 deletions lib/matplotlib/style/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,45 @@ def use(style):

%s
"""
style_alias = {'mpl20': 'default',
'mpl15': 'classic'}
if isinstance(style, (str, Path)) or hasattr(style, 'keys'):
# If name is a single str, Path or dict, make it a single element list.
styles = [style]
else:
styles = style

styles = (style_alias.get(s, s) if isinstance(s, str) else s
for s in styles)
for style in styles:
style_alias = {'mpl20': 'default', 'mpl15': 'classic'}

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 'seaborn0.8-<style>'. "
"Alternatively, directly use the seaborn API instead.")
s = s.replace("seaborn", "seaborn0.8")
return s

for style in map(fix_style, styles):
if not isinstance(style, (str, Path)):
_apply_style(style)
elif style == 'default':
Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,12 @@ def test_xkcd_cm():
with plt.xkcd():
assert mpl.rcParams["path.sketch"] == (1, 100, 2)
assert mpl.rcParams["path.sketch"] is None


def test_deprecated_seaborn_styles():
with mpl.style.context("seaborn0.8-bright"):
seaborn_bright = mpl.rcParams.copy()
assert mpl.rcParams != seaborn_bright
with pytest.warns(mpl._api.MatplotlibDeprecationWarning):
mpl.style.use("seaborn-bright")
assert mpl.rcParams == seaborn_bright
2 changes: 1 addition & 1 deletion tutorials/colors/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def demo(sty):


demo('default')
demo('seaborn')
demo('seaborn0.8')

###############################################################################
# The first color ``'C0'`` is the title. Each plot uses the second and third
Expand Down