Skip to content

Commit 5555f54

Browse files
committed
Merge pull request matplotlib#4381 from tacaswell/legend_rcparams_doc_tests
Legend rcparams doc tests
2 parents 7c7e614 + fb2f393 commit 5555f54

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

doc/users/whats_new/rcparams.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,17 @@ but not yet implemented.
1212

1313
Added "figure.titlesize" and "figure.titleweight" keys to rcParams
1414
``````````````````````````````````````````````````````````````````
15-
Two new keys were added to rcParams to control the default font size and weight
16-
used by the figure title (as emitted by ``pyplot.suptitle()``).
15+
16+
Two new keys were added to rcParams to control the default font size
17+
and weight used by the figure title (as emitted by
18+
``pyplot.suptitle()``).
19+
20+
Added ``legend.facecolor`` and ``legend.edgecolor`` keys to rcParams
21+
```````````````````````````````````````````````````````````````````
22+
23+
The new keys control colors (background and edge) of legend patches.
24+
The value ``'inherit'`` for these rcParams falls uses the value of
25+
``axes.facecolor`` and ``axes.edgecolor``.
1726

1827

1928
``image.composite_image`` added to rcParams
@@ -28,4 +37,3 @@ Added "toolmanager" to "toolbar" possible values
2837
````````````````````````````````````````````````
2938

3039
The new value enables the use of ``ToolManager``
31-

lib/matplotlib/tests/test_rcparams.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
import warnings
1010

1111
import matplotlib as mpl
12+
import matplotlib.pyplot as plt
1213
from matplotlib.tests import assert_str_equal
1314
from matplotlib.testing.decorators import cleanup, knownfailureif
15+
import matplotlib.colors as mcolors
1416
from nose.tools import assert_true, assert_raises, assert_equal
1517
from nose.plugins.skip import SkipTest
1618
import nose
@@ -180,6 +182,50 @@ def test_Bug_2543_newer_python():
180182
with mpl.rc_context():
181183
mpl.rcParams['svg.fonttype'] = True
182184

185+
186+
@cleanup
187+
def _legend_rcparam_helper(param_dict, target, get_func):
188+
with mpl.rc_context(param_dict):
189+
_, ax = plt.subplots()
190+
ax.plot(range(3), label='test')
191+
leg = ax.legend()
192+
assert_equal(getattr(leg.legendPatch, get_func)(), target)
193+
194+
195+
def test_legend_facecolor():
196+
get_func = 'get_facecolor'
197+
rcparam = 'legend.facecolor'
198+
test_values = [({rcparam: 'r'},
199+
mcolors.colorConverter.to_rgba('r')),
200+
({rcparam: 'inherit',
201+
'axes.facecolor': 'r'
202+
},
203+
mcolors.colorConverter.to_rgba('r')),
204+
({rcparam: 'g',
205+
'axes.facecolor': 'r'},
206+
mcolors.colorConverter.to_rgba('g'))
207+
]
208+
for rc_dict, target in test_values:
209+
yield _legend_rcparam_helper, rc_dict, target, get_func
210+
211+
212+
def test_legend_edgecolor():
213+
get_func = 'get_edgecolor'
214+
rcparam = 'legend.edgecolor'
215+
test_values = [({rcparam: 'r'},
216+
mcolors.colorConverter.to_rgba('r')),
217+
({rcparam: 'inherit',
218+
'axes.edgecolor': 'r'
219+
},
220+
mcolors.colorConverter.to_rgba('r')),
221+
({rcparam: 'g',
222+
'axes.facecolor': 'r'},
223+
mcolors.colorConverter.to_rgba('g'))
224+
]
225+
for rc_dict, target in test_values:
226+
yield _legend_rcparam_helper, rc_dict, target, get_func
227+
228+
183229
def test_Issue_1713():
184230
utf32_be = os.path.join(os.path.dirname(__file__),
185231
'test_utf32_be_rcparams.rc')

0 commit comments

Comments
 (0)