From 21b129fc241962e3e810280485a383768fd34fd8 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Fri, 1 Jan 2016 11:23:56 -0500 Subject: [PATCH 1/3] Fix #5777. Don't warn when applying default style --- lib/matplotlib/style/core.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/style/core.py b/lib/matplotlib/style/core.py index 90544639bf46..0bc6eb9e891a 100644 --- a/lib/matplotlib/style/core.py +++ b/lib/matplotlib/style/core.py @@ -98,7 +98,8 @@ def use(style): if not cbook.is_string_like(style): _apply_style(style) elif style == 'default': - _apply_style(rcParamsDefault) + with warnings.catch_warnings(record=True): + _apply_style(rcParamsDefault) elif style in library: _apply_style(library[style]) else: From 0a35fe46aa54bf4a5950dd9deb003546495424c5 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 4 Jan 2016 10:16:51 -0500 Subject: [PATCH 2/3] Don't use catch_warnings --- lib/matplotlib/style/core.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/matplotlib/style/core.py b/lib/matplotlib/style/core.py index 0bc6eb9e891a..a6b9c06d4542 100644 --- a/lib/matplotlib/style/core.py +++ b/lib/matplotlib/style/core.py @@ -43,13 +43,14 @@ 'savefig.directory', 'tk.window_focus', 'hardcopy.docstring']) -def _remove_blacklisted_style_params(d): +def _remove_blacklisted_style_params(d, warn=True): 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)) + if warn: + warnings.warn( + "Style includes a parameter, '{0}', that is not related " + "to style. Ignoring".format(key)) else: o[key] = val return o @@ -60,8 +61,8 @@ def is_style_file(filename): return STYLE_FILE_PATTERN.match(filename) is not None -def _apply_style(d): - mpl.rcParams.update(_remove_blacklisted_style_params(d)) +def _apply_style(d, warn=True): + mpl.rcParams.update(_remove_blacklisted_style_params(d, warn=warn)) def use(style): @@ -98,8 +99,7 @@ def use(style): if not cbook.is_string_like(style): _apply_style(style) elif style == 'default': - with warnings.catch_warnings(record=True): - _apply_style(rcParamsDefault) + _apply_style(rcParamsDefault, warn=False) elif style in library: _apply_style(library[style]) else: From c515a9d86520218d79c095dc840367966997e921 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 4 Jan 2016 14:27:15 -0500 Subject: [PATCH 3/3] Fix warning during test --- lib/matplotlib/tests/test_backend_qt4.py | 4 ++-- lib/matplotlib/tests/test_backend_qt5.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/tests/test_backend_qt4.py b/lib/matplotlib/tests/test_backend_qt4.py index e2fe57a8246b..5dfdfdf6cf46 100644 --- a/lib/matplotlib/tests/test_backend_qt4.py +++ b/lib/matplotlib/tests/test_backend_qt4.py @@ -7,7 +7,7 @@ from matplotlib.testing.decorators import cleanup, switch_backend from matplotlib.testing.decorators import knownfailureif from matplotlib._pylab_helpers import Gcf -import matplotlib.style as mstyle +import matplotlib import copy try: @@ -17,7 +17,7 @@ import mock try: - with mstyle.context({'backend': 'Qt4Agg'}): + with matplotlib.rc_context(rc={'backend': 'Qt4Agg'}): from matplotlib.backends.qt_compat import QtCore from matplotlib.backends.backend_qt4 import (MODIFIER_KEYS, diff --git a/lib/matplotlib/tests/test_backend_qt5.py b/lib/matplotlib/tests/test_backend_qt5.py index 1e6967122fa4..eefe86fd2001 100644 --- a/lib/matplotlib/tests/test_backend_qt5.py +++ b/lib/matplotlib/tests/test_backend_qt5.py @@ -6,7 +6,7 @@ from matplotlib.testing.decorators import cleanup, switch_backend from matplotlib.testing.decorators import knownfailureif from matplotlib._pylab_helpers import Gcf -import matplotlib.style as mstyle +import matplotlib import copy try: @@ -16,7 +16,7 @@ import mock try: - with mstyle.context({'backend': 'Qt5Agg'}): + with matplotlib.rc_context(rc={'backend': 'Qt5Agg'}): from matplotlib.backends.qt_compat import QtCore, __version__ from matplotlib.backends.backend_qt5 import (MODIFIER_KEYS, SUPER, ALT, CTRL, SHIFT)