Skip to content

Commit bbf8684

Browse files
author
mrkrd
committed
Merge pull request #1 from tacaswell/legend_rcparams
Legend rcparams
2 parents 7f2d297 + 4db02ca commit bbf8684

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

lib/matplotlib/rcsetup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,8 @@ def __call__(self, s):
661661
# the relative size of legend markers vs. original
662662
'legend.markerscale': [1.0, validate_float],
663663
'legend.shadow': [False, validate_bool],
664-
'legend.facecolor': ['w', validate_color], # background color; white
665-
'legend.edgecolor': ['k', validate_color], # edge color; black
664+
'legend.facecolor': [None, validate_color], # background color; white
665+
'legend.edgecolor': [None, validate_color], # edge color; black
666666

667667

668668
## tick properties

lib/matplotlib/tests/test_legend.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,35 @@ def test_legend_stackplot():
246246
ax.legend(loc=0)
247247

248248

249+
@cleanup
250+
def _test_rcparams_helper(test_rcparams, facecolor_target, edgecolor_target):
251+
with mpl.rc_context(test_rcparams):
252+
fig, ax = plt.subplots(1, 1)
253+
t = np.linspace(0, 2*np.pi)
254+
ax.plot(t, np.sin(t), label='sin')
255+
ax.plot(t, np.cos(t), label='cos')
256+
leg = ax.legend()
257+
258+
assert_equal(mpl.colors.colorConverter.to_rgba(facecolor_target),
259+
leg.legendPatch.get_facecolor())
260+
261+
assert_equal(mpl.colors.colorConverter.to_rgba(edgecolor_target),
262+
leg.legendPatch.get_edgecolor())
263+
264+
265+
def test_rcparams_():
266+
test_vals = [({}, mpl.rcParams['axes.facecolor'],
267+
mpl.rcParams['axes.edgecolor']),
268+
({'axes.facecolor': 'r', 'axes.edgecolor': 'c'}, 'r', 'c'),
269+
({'axes.facecolor': 'r', 'axes.edgecolor': 'c',
270+
'legend.facecolor': 'w', 'legend.edgecolor': 'k'},
271+
'w', 'k'),
272+
]
273+
274+
for rc_dict, face, edge in test_vals:
275+
yield _test_rcparams_helper, rc_dict, face, edge
276+
277+
249278
if __name__ == '__main__':
250279
import nose
251280
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)