| 1 | diff --git a/lib/matplotlib/style/core.py b/lib/matplotlib/style/core.py |
| 2 | --- a/lib/matplotlib/style/core.py |
| 3 | +++ b/lib/matplotlib/style/core.py |
| 4 | @@ -43,6 +43,32 @@ class __getattr__: |
| 5 | 'toolbar', 'timezone', 'figure.max_open_warning', |
| 6 | 'figure.raise_window', 'savefig.directory', 'tk.window_focus', |
| 7 | 'docstring.hardcopy', 'date.epoch'} |
| 8 | +_DEPRECATED_SEABORN_STYLES = { |
| 9 | + s: s.replace("seaborn", "seaborn-v0_8") |
| 10 | + for s in [ |
| 11 | + "seaborn", |
| 12 | + "seaborn-bright", |
| 13 | + "seaborn-colorblind", |
| 14 | + "seaborn-dark", |
| 15 | + "seaborn-darkgrid", |
| 16 | + "seaborn-dark-palette", |
| 17 | + "seaborn-deep", |
| 18 | + "seaborn-muted", |
| 19 | + "seaborn-notebook", |
| 20 | + "seaborn-paper", |
| 21 | + "seaborn-pastel", |
| 22 | + "seaborn-poster", |
| 23 | + "seaborn-talk", |
| 24 | + "seaborn-ticks", |
| 25 | + "seaborn-white", |
| 26 | + "seaborn-whitegrid", |
| 27 | + ] |
| 28 | +} |
| 29 | +_DEPRECATED_SEABORN_MSG = ( |
| 30 | + "The seaborn styles shipped by Matplotlib are deprecated since %(since)s, " |
| 31 | + "as they no longer correspond to the styles shipped by seaborn. However, " |
| 32 | + "they will remain available as 'seaborn-v0_8-<style>'. Alternatively, " |
| 33 | + "directly use the seaborn API instead.") |
| 34 | |
| 35 | |
| 36 | def _remove_blacklisted_style_params(d, warn=True): |
| 37 | @@ -113,31 +139,9 @@ def use(style): |
| 38 | def fix_style(s): |
| 39 | if isinstance(s, str): |
| 40 | s = style_alias.get(s, s) |
| 41 | - if s in [ |
| 42 | - "seaborn", |
| 43 | - "seaborn-bright", |
| 44 | - "seaborn-colorblind", |
| 45 | - "seaborn-dark", |
| 46 | - "seaborn-darkgrid", |
| 47 | - "seaborn-dark-palette", |
| 48 | - "seaborn-deep", |
| 49 | - "seaborn-muted", |
| 50 | - "seaborn-notebook", |
| 51 | - "seaborn-paper", |
| 52 | - "seaborn-pastel", |
| 53 | - "seaborn-poster", |
| 54 | - "seaborn-talk", |
| 55 | - "seaborn-ticks", |
| 56 | - "seaborn-white", |
| 57 | - "seaborn-whitegrid", |
| 58 | - ]: |
| 59 | - _api.warn_deprecated( |
| 60 | - "3.6", message="The seaborn styles shipped by Matplotlib " |
| 61 | - "are deprecated since %(since)s, as they no longer " |
| 62 | - "correspond to the styles shipped by seaborn. However, " |
| 63 | - "they will remain available as 'seaborn-v0_8-<style>'. " |
| 64 | - "Alternatively, directly use the seaborn API instead.") |
| 65 | - s = s.replace("seaborn", "seaborn-v0_8") |
| 66 | + if s in _DEPRECATED_SEABORN_STYLES: |
| 67 | + _api.warn_deprecated("3.6", message=_DEPRECATED_SEABORN_MSG) |
| 68 | + s = _DEPRECATED_SEABORN_STYLES[s] |
| 69 | return s |
| 70 | |
| 71 | for style in map(fix_style, styles): |
| 72 | @@ -244,17 +248,26 @@ def update_nested_dict(main_dict, new_dict): |
| 73 | return main_dict |
| 74 | |
| 75 | |
| 76 | +class _StyleLibrary(dict): |
| 77 | + def __getitem__(self, key): |
| 78 | + if key in _DEPRECATED_SEABORN_STYLES: |
| 79 | + _api.warn_deprecated("3.6", message=_DEPRECATED_SEABORN_MSG) |
| 80 | + key = _DEPRECATED_SEABORN_STYLES[key] |
| 81 | + |
| 82 | + return dict.__getitem__(self, key) |
| 83 | + |
| 84 | + |
| 85 | # Load style library |
| 86 | # ================== |
| 87 | _base_library = read_style_directory(BASE_LIBRARY_PATH) |
| 88 | -library = None |
| 89 | +library = _StyleLibrary() |
| 90 | available = [] |
| 91 | |
| 92 | |
| 93 | def reload_library(): |
| 94 | """Reload the style library.""" |
| 95 | - global library |
| 96 | - library = update_user_library(_base_library) |
| 97 | + library.clear() |
| 98 | + library.update(update_user_library(_base_library)) |
| 99 | available[:] = sorted(library.keys()) |
| 100 | |
| 101 | |