8000 Fix #4855: Blacklist rcParams that aren't style by mdboom · Pull Request #5440 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 6 commits into from
Dec 31, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix #4855: Blacklist rcParams that aren't style
  • Loading branch information
mdboom committed Nov 8, 2015
commit c90bcfb00731e9808e7d5a12ec2574cec948bf24
22 changes: 19 additions & 3 deletions lib/matplotlib/style/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Copy link
Member

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?

Copy link
Member Author

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).



def _blacklist_style_params(d):
Copy link
Member

Choose a reason for hiding this comment

The 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 _screened_style_params or _valid_style_params?

return dict((k, v) for (k, v) in d.items() if k not in STYLE_BLACKLIST)
Copy link
Member

Choose a reason for hiding this comment

The 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))
Copy link
Member

Choose a reason for hiding this comment

The 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.

Expand Down Expand Up @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. That makes sense.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

61D8
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 "
Expand Down
0