|
9 | 9 | import warnings
|
10 | 10 |
|
11 | 11 | import matplotlib as mpl
|
| 12 | +import matplotlib.pyplot as plt |
12 | 13 | from matplotlib.tests import assert_str_equal
|
13 | 14 | from matplotlib.testing.decorators import cleanup, knownfailureif
|
| 15 | +import matplotlib.colors as mcolors |
14 | 16 | from nose.tools import assert_true, assert_raises, assert_equal
|
15 | 17 | from nose.plugins.skip import SkipTest
|
16 | 18 | import nose
|
@@ -180,6 +182,50 @@ def test_Bug_2543_newer_python():
|
180 | 182 | with mpl.rc_context():
|
181 | 183 | mpl.rcParams['svg.fonttype'] = True
|
182 | 184 |
|
| 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 | + |
183 | 229 | def test_Issue_1713():
|
184 | 230 | utf32_be = os.path.join(os.path.dirname(__file__),
|
185 | 231 | 'test_utf32_be_rcparams.rc')
|
|
0 commit comments