-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix #4855: Blacklist rcParams that aren't style #5440
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
Changes from 1 commit
c90bcfb
22f99bb
fdae5de
e68d239
0946c1c
d9d1671
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,11 +34,27 @@ | |
STYLE_FILE_PATTERN = re.compile('([\S]+).%s$' % STYLE_EXTENSION) | ||
|
||
|
||
# A list of rcParams that should not be applied from styles | ||
STYLE_BLACKLIST = set([ | ||
'interactive', 'backend', 'backend.qt4', 'webagg.port', | ||
'webagg.port_retries', 'webagg.open_in_browser', 'backend_fallback', | ||
'toolbar', 'timezone', 'datapath', 'figure.max_open_warning', | ||
'savefig.directory', 'tk.window_focus', 'hardcopy.docstring']) | ||
|
||
|
||
def _blacklist_style_params(d): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name is not so clear in indicating that a dict of valid params will be returned; how about |
||
return dict((k, v) for (k, v) in d.items() if k not in STYLE_BLACKLIST) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to raise a warning if a a blacklisted key is found? |
||
|
||
|
||
def is_style_file(filename): | ||
"""Return True if the filename looks like a style file.""" | ||
return STYLE_FILE_PATTERN.match(filename) is not None | ||
|
||
|
||
def _apply_style(d): | ||
mpl.rcParams.use(blacklist_style_params(d)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing a leading underscore. |
||
|
||
|
||
def use(style): | ||
"""Use matplotlib style settings from a style specification. | ||
|
||
|
@@ -71,18 +87,18 @@ def use(style): | |
|
||
for style in styles: | ||
if not cbook.is_string_like(style): | ||
mpl.rcParams.update(style) | ||
_apply_style(style) | ||
continue | ||
elif style == 'default': | ||
mpl.rcdefaults() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a bit of a disconnect here. rcdefaults() is more than just style stuff, but it doesn't make sense to blacklist entries there, either, does it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mdboom, I think @WeatherGod has a good point here: 'default' style should modify only non-blacklisted things, shouldn't it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. That makes sense. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
continue | ||
|
||
if style in library: | ||
mpl.rcParams.update(library[style]) | ||
_apply_style(library[style]) | ||
else: | ||
try: | ||
rc = rc_params_from_file(style, use_default_template=False) | ||
mpl.rcParams.update(rc) | ||
_apply_style(rc) | ||
except IOError: | ||
msg = ("'%s' not found in the style library and input is " | ||
"not a valid URL or path. See `style.available` for " | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about the default keymappings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, I thought using style might be handy, e.g. an Emacs key style (not that one could do that given our current framework, but you get the idea).