Skip to content

Commit 5743492

Browse files
authored
Merge pull request #22317 from anntzer/snsty
Rename outdated seaborn styles.
2 parents 9844e9f + 06c92b8 commit 5743492

20 files changed

+51
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
seaborn styles renamed
2+
~~~~~~~~~~~~~~~~~~~~~~
3+
Matplotlib currently ships many style files inspired from the seaborn
4+
library ("seaborn", "seaborn-bright", "seaborn-colorblind", etc.) but they
5+
have gone out of sync with the library itself since the release of seaborn
6+
0.9. To prevent confusion, the style files have been renamed "seaborn0.8",
7+
"seaborn0.8-bright", "seaborn0.8-colorblind", etc. Users are encouraged to
8+
directly use seaborn to access the up-to-date styles.

lib/matplotlib/style/core.py

+33-5
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,45 @@ def use(style):
102102
103103
%s
104104
"""
105-
style_alias = {'mpl20': 'default',
106-
'mpl15': 'classic'}
107105
if isinstance(style, (str, Path)) or hasattr(style, 'keys'):
108106
# If name is a single str, Path or dict, make it a single element list.
109107
styles = [style]
110108
else:
111109
styles = style
112110

113-
styles = (style_alias.get(s, s) if isinstance(s, str) else s
114-
for s in styles)
115-
for style in styles:
111+
style_alias = {'mpl20': 'default', 'mpl15': 'classic'}
112+
113+
def fix_style(s):
114+
if isinstance(s, str):
115+
s = style_alias.get(s, s)
116+
if s in [
117+
"seaborn",
118+
"seaborn-bright",
119+
"seaborn-colorblind",
120+
"seaborn-dark",
121+
"seaborn-darkgrid",
122+
"seaborn-dark-palette",
123+
"seaborn-deep",
124+
"seaborn-muted",
125+
"seaborn-notebook",
126+
"seaborn-paper",
127+
"seaborn-pastel",
128+
"seaborn-poster",
129+
"seaborn-talk",
130+
"seaborn-ticks",
131+
"seaborn-white",
132+
"seaborn-whitegrid",
133+
]:
134+
_api.warn_deprecated(
135+
"3.6", message="The seaborn styles shipped by Matplotlib "
136+
"are deprecated since %(since)s, as they no longer "
137+
"correspond to the styles shipped by seaborn. However, "
138+
"they will remain available as 'seaborn0.8-<style>'. "
139+
"Alternatively, directly use the seaborn API instead.")
140+
s = s.replace("seaborn", "seaborn0.8")
141+
return s
142+
143+
for style in map(fix_style, styles):
116144
if not isinstance(style, (str, Path)):
117145
_apply_style(style)
118146
elif style == 'default':

lib/matplotlib/tests/test_style.py

+9
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,12 @@ def test_xkcd_cm():
174174
with plt.xkcd():
175175
assert mpl.rcParams["path.sketch"] == (1, 100, 2)
176176
assert mpl.rcParams["path.sketch"] is None
177+
178+
179+
def test_deprecated_seaborn_styles():
180+
with mpl.style.context("seaborn0.8-bright"):
181+
seaborn_bright = mpl.rcParams.copy()
182+
assert mpl.rcParams != seaborn_bright
183+
with pytest.warns(mpl._api.MatplotlibDeprecationWarning):
184+
mpl.style.use("seaborn-bright")
185+
assert mpl.rcParams == seaborn_bright

tutorials/colors/colors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def demo(sty):
134134

135135

136136
demo('default')
137-
demo('seaborn')
137+
demo('seaborn0.8')
138138

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

0 commit comments

Comments
 (0)