From 3a820882b1f177a64e534cc4880e90596c694249 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sat, 25 Apr 2015 23:25:08 -0400 Subject: [PATCH 1/3] DOC : document new rcparams --- doc/users/whats_new/rcparams.rst | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/doc/users/whats_new/rcparams.rst b/doc/users/whats_new/rcparams.rst index d7641c76b83f..38ffeeeadef6 100644 --- a/doc/users/whats_new/rcparams.rst +++ b/doc/users/whats_new/rcparams.rst @@ -12,8 +12,17 @@ but not yet implemented. Added "figure.titlesize" and "figure.titleweight" keys to rcParams `````````````````````````````````````````````````````````````````` -Two new keys were added to rcParams to control the default font size and weight -used by the figure title (as emitted by ``pyplot.suptitle()``). + +Two new keys were added to rcParams to control the default font size +and weight used by the figure title (as emitted by +``pyplot.suptitle()``). + +Added ``legend.facecolor`` and ``legend.edgecolor`` keys to rcParams +``````````````````````````````````````````````````````````````````` + +The new keys control colors (background and edge) of legend patches. +The value ``'inherit'`` for these rcParams falls uses the value of +``axes.facecolor`` and ``axes.edgecolor``. ``image.composite_image`` added to rcParams @@ -28,4 +37,3 @@ Added "toolmanager" to "toolbar" possible values ```````````````````````````````````````````````` The new value enables the use of ``ToolManager`` - From 31313c698f89be4c1d95874352d23982605afe66 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sat, 25 Apr 2015 23:58:14 -0400 Subject: [PATCH 2/3] TST : minimal tests of legend.facecolor and legend.edegcolor --- lib/matplotlib/tests/test_rcparams.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index 8265cb77dad2..bf9a009fa47b 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -9,6 +9,7 @@ import warnings import matplotlib as mpl +import matplotlib.pyplot as plt from matplotlib.tests import assert_str_equal from matplotlib.testing.decorators import cleanup, knownfailureif from nose.tools import assert_true, assert_raises, assert_equal @@ -180,6 +181,25 @@ def test_Bug_2543_newer_python(): with mpl.rc_context(): mpl.rcParams['svg.fonttype'] = True + +@cleanup +def test_legend_facecolor(): + with mpl.rc_context({'legend.facecolor': 'r'}): + _, ax = plt.subplots() + ax.plot(range(3), label='test') + leg = ax.legend() + assert_equal(leg.legendPatch.get_facecolor(), (1, 0, 0, 1)) + + +@cleanup +def test_legend_edgecolor(): + with mpl.rc_context({'legend.edgecolor': 'r'}): + _, ax = plt.subplots() + ax.plot(range(3), label='test') + leg = ax.legend() + assert_equal(leg.legendPatch.get_edgecolor(), (1, 0, 0, 1)) + + def test_Issue_1713(): utf32_be = os.path.join(os.path.dirname(__file__), 'test_utf32_be_rcparams.rc') From fb2f3938e9349c1159dcf52872c0c794358ccd46 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Sun, 26 Apr 2015 00:35:01 -0400 Subject: [PATCH 3/3] TST : more testing on legend.{face,edge}color --- lib/matplotlib/tests/test_rcparams.py | 44 +++++++++++++++++++++------ 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index bf9a009fa47b..0a294e46b0e0 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -12,6 +12,7 @@ import matplotlib.pyplot as plt from matplotlib.tests import assert_str_equal from matplotlib.testing.decorators import cleanup, knownfailureif +import matplotlib.colors as mcolors from nose.tools import assert_true, assert_raises, assert_equal from nose.plugins.skip import SkipTest import nose @@ -183,21 +184,46 @@ def test_Bug_2543_newer_python(): @cleanup -def test_legend_facecolor(): - with mpl.rc_context({'legend.facecolor': 'r'}): +def _legend_rcparam_helper(param_dict, target, get_func): + with mpl.rc_context(param_dict): _, ax = plt.subplots() ax.plot(range(3), label='test') leg = ax.legend() - assert_equal(leg.legendPatch.get_facecolor(), (1, 0, 0, 1)) + assert_equal(getattr(leg.legendPatch, get_func)(), target) + + +def test_legend_facecolor(): + get_func = 'get_facecolor' + rcparam = 'legend.facecolor' + test_values = [({rcparam: 'r'}, + mcolors.colorConverter.to_rgba('r')), + ({rcparam: 'inherit', + 'axes.facecolor': 'r' + }, + mcolors.colorConverter.to_rgba('r')), + ({rcparam: 'g', + 'axes.facecolor': 'r'}, + mcolors.colorConverter.to_rgba('g')) + ] + for rc_dict, target in test_values: + yield _legend_rcparam_helper, rc_dict, target, get_func -@cleanup def test_legend_edgecolor(): - with mpl.rc_context({'legend.edgecolor': 'r'}): - _, ax = plt.subplots() - ax.plot(range(3), label='test') - leg = ax.legend() - assert_equal(leg.legendPatch.get_edgecolor(), (1, 0, 0, 1)) + get_func = 'get_edgecolor' + rcparam = 'legend.edgecolor' + test_values = [({rcparam: 'r'}, + mcolors.colorConverter.to_rgba('r')), + ({rcparam: 'inherit', + 'axes.edgecolor': 'r' + }, + mcolors.colorConverter.to_rgba('r')), + ({rcparam: 'g', + 'axes.facecolor': 'r'}, + mcolors.colorConverter.to_rgba('g')) + ] + for rc_dict, target in test_values: + yield _legend_rcparam_helper, rc_dict, target, get_func def test_Issue_1713():