From 695323e3579aa2a8774b89f80709020e02c5abba Mon Sep 17 00:00:00 2001 From: WANG Aiyong Date: Thu, 9 Nov 2017 21:32:21 +0800 Subject: [PATCH 1/3] Make legend title fontsize obey fontsize kwarg by default As the issue [#8699](https://github.com/matplotlib/matplotlib/issues/8699) from long time ago stats, I often found this annoying. Seems like nobody is against this idea, and it is a really simple modification. So I'm pulling a request. --- lib/matplotlib/legend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index 269f93f345dd..ed8ac9f7612c 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -703,7 +703,7 @@ def __init__(self, parent, handles, labels, self.get_frame().set_alpha(framealpha) self._loc = loc - self.set_title(title) + self.set_title(title, self.prop) self._last_fontsize_points = self._fontsize self._draggable = None From 50bba52c433407f8de309914ec324e8176105d16 Mon Sep 17 00:00:00 2001 From: WANG Aiyong Date: Mon, 13 Nov 2017 19:33:39 +0800 Subject: [PATCH 2/3] Update the test_legend.py Set the fontsize of legend title back to 10, in order to pass thhose tests. --- lib/matplotlib/tests/test_legend.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/tests/test_legend.py b/lib/matplotlib/tests/test_legend.py index da9b072aeef0..67f228af0b02 100644 --- a/lib/matplotlib/tests/test_legend.py +++ b/lib/matplotlib/tests/test_legend.py @@ -156,8 +156,9 @@ def test_fancy(): plt.plot([5] * 10, 'o--', label='XX') plt.errorbar(np.arange(10), np.arange(10), xerr=0.5, yerr=0.5, label='XX') - plt.legend(loc="center left", bbox_to_anchor=[1.0, 0.5], + lg = plt.legend(loc="center left", bbox_to_anchor=[1.0, 0.5], ncol=2, shadow=True, title="My legend", numpoints=1) + lg.get_title().set_fontsize(10) @image_comparison(baseline_images=['framealpha'], remove_text=True) @@ -175,15 +176,17 @@ def test_rc(): plt.figure() ax = plt.subplot(121) ax.scatter(np.arange(10), np.arange(10, 0, -1), label='three') - ax.legend(loc="center left", bbox_to_anchor=[1.0, 0.5], + lg = ax.legend(loc="center left", bbox_to_anchor=[1.0, 0.5], title="My legend") + lg.get_title().set_fontsize(10) mpl.rcParams['legend.scatterpoints'] = 1 plt.figure() ax = plt.subplot(121) ax.scatter(np.arange(10), np.arange(10, 0, -1), label='one') - ax.legend(loc="center left", bbox_to_anchor=[1.0, 0.5], + lg = ax.legend(loc="center left", bbox_to_anchor=[1.0, 0.5], title="My legend") + lg.get_title().set_fontsize(10) @image_comparison(baseline_images=['legend_expand'], remove_text=True) From 5ce035ee1381da4a445b7f3f74c4b83227fafd92 Mon Sep 17 00:00:00 2001 From: WANG Aiyong Date: Tue, 14 Nov 2017 08:06:41 +0800 Subject: [PATCH 3/3] update test_legend.py Maybe the default fontsize is 12, let me see if this passes. --- lib/matplotlib/tests/test_legend.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/tests/test_legend.py b/lib/matplotlib/tests/test_legend.py index 67f228af0b02..28fa3e3e5230 100644 --- a/lib/matplotlib/tests/test_legend.py +++ b/lib/matplotlib/tests/test_legend.py @@ -158,7 +158,7 @@ def test_fancy(): yerr=0.5, label='XX') lg = plt.legend(loc="center left", bbox_to_anchor=[1.0, 0.5], ncol=2, shadow=True, title="My legend", numpoints=1) - lg.get_title().set_fontsize(10) + lg.get_title().set_fontsize(12) @image_comparison(baseline_images=['framealpha'], remove_text=True) @@ -178,7 +178,7 @@ def test_rc(): ax.scatter(np.arange(10), np.arange(10, 0, -1), label='three') lg = ax.legend(loc="center left", bbox_to_anchor=[1.0, 0.5], title="My legend") - lg.get_title().set_fontsize(10) + lg.get_title().set_fontsize(12) mpl.rcParams['legend.scatterpoints'] = 1 plt.figure() @@ -186,7 +186,7 @@ def test_rc(): ax.scatter(np.arange(10), np.arange(10, 0, -1), label='one') lg = ax.legend(loc="center left", bbox_to_anchor=[1.0, 0.5], title="My legend") - lg.get_title().set_fontsize(10) + lg.get_title().set_fontsize(12) @image_comparison(baseline_images=['legend_expand'], remove_text=True)