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

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
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions 11 doc/users/whats_new/style_blacklist.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Style parameter blacklist
-------------------------

In order to prevent unexpected consequences from using a style, style
files are no longer able to set parameters that affect things
unrelated to style. These parameters include::

'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'
12 changes: 1 addition & 11 deletions 12 lib/matplotlib/mpl-data/stylelib/classic.mplstyle
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,6 @@ figure.facecolor : 0.75 # figure facecolor; 0.75 is scalar gray
figure.edgecolor : w # figure edgecolor
figure.autolayout : False # When True, automatically adjust subplot
# parameters to make the plot fit the figure
figure.max_open_warning : 20 # The maximum number of figures to open through
# the pyplot interface before emitting a warning.
# If less than one this feature is disabled.
figure.frameon : True

# The figure subplot parameters. All dimensions are a fraction of the
Expand Down Expand Up @@ -385,18 +382,13 @@ savefig.bbox : standard # 'tight' or 'standard'.
# use ffmpeg_file instead
savefig.pad_inches : 0.1 # Padding to be used when bbox is set to 'tight'
savefig.jpeg_quality: 95 # when a jpeg is saved, the default quality parameter.
savefig.directory : ~ # default directory in savefig dialog box,
# leave empty to always use current working directory
savefig.transparent : False # setting that controls whether figures are saved with a
# transparent background by default
savefig.frameon : True
savefig.orientation : portrait

nbagg.transparent: True

# tk backend params
tk.window_focus : False # Maintain shell focus for TkAgg

# ps backend params
ps.papersize : letter # auto, letter, legal, ledger, A0-A10, B0-B10
ps.useafm : False # use of afm fonts, results in small files
Expand All @@ -418,7 +410,7 @@ pdf.use14corefonts : False
pgf.debug : False
pgf.texsystem : xelatex
pgf.rcfonts : True
pgf.preamble :
pgf.preamble :

# svg backend params
svg.image_inline : True # write raster image data directly into the svg file
Expand Down Expand Up @@ -467,8 +459,6 @@ keymap.yscale : l # toggle scaling of y-axes ('log'/'linear')
keymap.xscale : k, L # toggle scaling of x-axes ('log'/'linear')
keymap.all_axes : a # enable all axes

toolbar: toolbar2

###ANIMATION settings
animation.writer : ffmpeg # MovieWriter 'backend' to use
animation.codec : mpeg4 # Codec to use for writing movie
Expand Down
40 changes: 31 additions & 9 deletions 40 lib/matplotlib/style/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
import os
import re
import contextlib
import warnings

import matplotlib as mpl
from matplotlib import cbook
from matplotlib import rc_params_from_file
from matplotlib import rc_params_from_file, rcParamsDefault


__all__ = ['use', 'context', 'available', 'library', 'reload_library']
Expand All @@ -34,11 +35,35 @@
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 _remove_blacklisted_style_params(d):
o = {}
for key, val in d.items():
if key in STYLE_BLACKLIST:
warnings.warn(
"Style includes a parameter, '{0}', that is not related to "
"style. Ignoring".format(key))
else:
o[key] = val
return o


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.update(_remove_blacklisted_style_params(d))


def use(style):
"""Use matplotlib style settings from a style specification.

Expand Down Expand Up @@ -71,18 +96,15 @@ def use(style):

for style in styles:
if not cbook.is_string_like(style):
mpl.rcParams.update(style)
continue
_apply_style(style)
elif style == 'default':
mpl.rcdefaults()
continue

if style in library:
mpl.rcParams.update(library[style])
_apply_style(rcParamsDefault)
elif style in library:
_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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.