Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8decc8c

Browse filesBrowse files
committed
Merge pull request #5440 from mdboom/blacklist-style-params
Fix #4855: Blacklist rcParams that aren't style
2 parents ce0bd39 + d9d1671 commit 8decc8c
Copy full SHA for 8decc8c

File tree

Expand file treeCollapse file tree

3 files changed

+42
-19
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+42
-19
lines changed
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Style parameter blacklist
2+
-------------------------
3+
4+
In order to prevent unexpected consequences from using a style, style
5+
files are no longer able to set parameters that affect things
6+
unrelated to style. These parameters include::
7+
8+
'interactive', 'backend', 'backend.qt4', 'webagg.port',
9+
'webagg.port_retries', 'webagg.open_in_browser', 'backend_fallback',
10+
'toolbar', 'timezone', 'datapath', 'figure.max_open_warning',
11+
'savefig.directory', 'tk.window_focus', 'hardcopy.docstring'

‎lib/matplotlib/mpl-data/stylelib/classic.mplstyle

Copy file name to clipboardExpand all lines: lib/matplotlib/mpl-data/stylelib/classic.mplstyle
-10Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,6 @@ figure.facecolor : 0.75 # figure facecolor; 0.75 is scalar gray
286286
figure.edgecolor : w # figure edgecolor
287287
figure.autolayout : False # When True, automatically adjust subplot
288288
# parameters to make the plot fit the figure
289-
figure.max_open_warning : 20 # The maximum number of figures to open through
290-
# the pyplot interface before emitting a warning.
291-
# If less than one this feature is disabled.
292289
figure.frameon : True
293290

294291
# The figure subplot parameters. All dimensions are a fraction of the
@@ -393,18 +390,13 @@ savefig.bbox : standard # 'tight' or 'standard'.
393390
# use ffmpeg_file instead
394391
savefig.pad_inches : 0.1 # Padding to be used when bbox is set to 'tight'
395392
savefig.jpeg_quality: 95 # when a jpeg is saved, the default quality parameter.
396-
savefig.directory : ~ # default directory in savefig dialog box,
397-
# leave empty to always use current working directory
398393
savefig.transparent : False # setting that controls whether figures are saved with a
399394
# transparent background by default
400395
savefig.frameon : True
401396
savefig.orientation : portrait
402397

403398
nbagg.transparent: True
404399

405-
# tk backend params
406-
tk.window_focus : False # Maintain shell focus for TkAgg
407-
408400
# ps backend params
409401
ps.papersize : letter # auto, letter, legal, ledger, A0-A10, B0-B10
410402
ps.useafm : False # use of afm fonts, results in small files
@@ -475,8 +467,6 @@ keymap.yscale : l # toggle scaling of y-axes ('log'/'linear')
475467
keymap.xscale : k, L # toggle scaling of x-axes ('log'/'linear')
476468
keymap.all_axes : a # enable all axes
477469

478-
toolbar: toolbar2
479-
480470
###ANIMATION settings
481471
animation.writer : ffmpeg # MovieWriter 'backend' to use
482472
animation.codec : mpeg4 # Codec to use for writing movie

‎lib/matplotlib/style/core.py

Copy file name to clipboardExpand all lines: lib/matplotlib/style/core.py
+31-9Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
import os
1919
import re
2020
import contextlib
21+
import warnings
2122

2223
import matplotlib as mpl
2324
from matplotlib import cbook
24-
from matplotlib import rc_params_from_file
25+
from matplotlib import rc_params_from_file, rcParamsDefault
2526

2627

2728
__all__ = ['use', 'context', 'available', 'library', 'reload_library']
@@ -34,11 +35,35 @@
3435
STYLE_FILE_PATTERN = re.compile('([\S]+).%s$' % STYLE_EXTENSION)
3536

3637

38+
# A list of rcParams that should not be applied from styles
39+
STYLE_BLACKLIST = set([
40+
'interactive', 'backend', 'backend.qt4', 'webagg.port',
41+
'webagg.port_retries', 'webagg.open_in_browser', 'backend_fallback',
42+
'toolbar', 'timezone', 'datapath', 'figure.max_open_warning',
43+
'savefig.directory', 'tk.window_focus', 'hardcopy.docstring'])
44+
45+
46+
def _remove_blacklisted_style_params(d):
47+
o = {}
48+
for key, val in d.items():
49+
if key in STYLE_BLACKLIST:
50+
warnings.warn(
51+
"Style includes a parameter, '{0}', that is not related to "
52+
"style. Ignoring".format(key))
53+
else:
54+
o[key] = val
55+
return o
56+
57+
3758
def is_style_file(filename):
3859
"""Return True if the filename looks like a style file."""
3960
return STYLE_FILE_PATTERN.match(filename) is not None
4061

4162

63+
def _apply_style(d):
64+
mpl.rcParams.update(_remove_blacklisted_style_params(d))
65+
66+
4267
def use(style):
4368
"""Use matplotlib style settings from a style specification.
4469
@@ -71,18 +96,15 @@ def use(style):
7196

7297
for style in styles:
7398
if not cbook.is_string_like(style):
74-
mpl.rcParams.update(style)
75-
continue
99+
_apply_style(style)
76100
elif style == 'default':
77-
mpl.rcdefaults()
78-
continue
79-
80-
if style in library:
81-
mpl.rcParams.update(library[style])
101+
_apply_style(rcParamsDefault)
102+
elif style in library:
103+
_apply_style(library[style])
82104
else:
83105
try:
84106
rc = rc_params_from_file(style, use_default_template=False)
85-
mpl.rcParams.update(rc)
107+
_apply_style(rc)
86108
except IOError:
87109
msg = ("'%s' not found in the style library and input is "
88110
"not a valid URL or path. See `style.available` for "

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.