|
34 | 34 | STYLE_FILE_PATTERN = re.compile('([\S]+).%s$' % STYLE_EXTENSION)
|
35 | 35 |
|
36 | 36 |
|
| 37 | +# A list of rcParams that should not be applied from styles |
| 38 | +STYLE_BLACKLIST = set([ |
| 39 | + 'interactive', 'backend', 'backend.qt4', 'webagg.port', |
| 40 | + 'webagg.port_retries', 'webagg.open_in_browser', 'backend_fallback', |
| 41 | + 'toolbar', 'timezone', 'datapath', 'figure.max_open_warning', |
| 42 | + 'savefig.directory', 'tk.window_focus', 'hardcopy.docstring']) |
| 43 | + |
| 44 | + |
| 45 | +def _blacklist_style_params(d): |
| 46 | + return dict((k, v) for (k, v) in d.items() if k not in STYLE_BLACKLIST) |
| 47 | + |
| 48 | + |
37 | 49 | def is_style_file(filename):
|
38 | 50 | """Return True if the filename looks like a style file."""
|
39 | 51 | return STYLE_FILE_PATTERN.match(filename) is not None
|
40 | 52 |
|
41 | 53 |
|
| 54 | +def _apply_style(d): |
| 55 | + mpl.rcParams.use(blacklist_style_params(d)) |
| 56 | + |
| 57 | + |
42 | 58 | def use(style):
|
43 | 59 | """Use matplotlib style settings from a style specification.
|
44 | 60 |
|
@@ -71,18 +87,18 @@ def use(style):
|
71 | 87 |
|
72 | 88 | for style in styles:
|
73 | 89 | if not cbook.is_string_like(style):
|
74 |
| - mpl.rcParams.update(style) |
| 90 | + _apply_style(style) |
75 | 91 | continue
|
76 | 92 | elif style == 'default':
|
77 | 93 | mpl.rcdefaults()
|
78 | 94 | continue
|
79 | 95 |
|
80 | 96 | if style in library:
|
81 |
| - mpl.rcParams.update(library[style]) |
| 97 | + _apply_style(library[style]) |
82 | 98 | else:
|
83 | 99 | try:
|
84 | 100 | rc = rc_params_from_file(style, use_default_template=False)
|
85 |
| - mpl.rcParams.update(rc) |
| 101 | + _apply_style(rc) |
86 | 102 | except IOError:
|
87 | 103 | msg = ("'%s' not found in the style library and input is "
|
88 | 104 | "not a valid URL or path. See `style.available` for "
|
|
0 commit comments