From 04ef849b954616cc83797af33fde220361cdcd68 Mon Sep 17 00:00:00 2001 From: s0vereign Date: Fri, 4 Aug 2017 12:21:43 +0200 Subject: [PATCH 1/6] Added the Fix for Issue 8943 and a simple testcase. --- lib/matplotlib/legend.py | 9 ++++++++- lib/matplotlib/tests/test_legend.py | 8 ++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index e649741162cc..ff13a1c5ccc5 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -259,6 +259,7 @@ def __init__(self, parent, handles, labels, else: self.prop = prop + self._fontsize = self.prop.get_size_in_points() self.texts = [] @@ -384,8 +385,14 @@ def __init__(self, parent, handles, labels, # init with null renderer self._init_legend_box(handles, labels, markerfirst) + # If shadow is activated also use framealpha if not + # explicitly passed. See Issue 8943 + if framealpha is None: - self.get_frame().set_alpha(rcParams["legend.framealpha"]) + if shadow is True: + self.framealpha = 1 + else: + self.get_frame().set_alpha(rcParams["legend.framealpha"]) else: self.get_frame().set_alpha(framealpha) diff --git a/lib/matplotlib/tests/test_legend.py b/lib/matplotlib/tests/test_legend.py index 5772ad19fbfb..8b31e2c3a2ec 100644 --- a/lib/matplotlib/tests/test_legend.py +++ b/lib/matplotlib/tests/test_legend.py @@ -359,3 +359,11 @@ def test_handler_numpoints(): fig, ax = plt.subplots() ax.plot(range(5), label='test') ax.legend(numpoints=0.5) + + +def test_shadow_framealpha(): + '''Test if framealpha is activated when shadow is True and framealpha is not explicitly passed''' + fig, ax = plt.subplots() + ax.plot(range(100),label="test") + leg = ax.legend(shadow=True, facecolor='w') + assert leg.framealpha == 1 From 080863425bea242b7a1b8b3cd735350a94577e9f Mon Sep 17 00:00:00 2001 From: s0vereign Date: Fri, 4 Aug 2017 12:32:32 +0200 Subject: [PATCH 2/6] removed unecessary lines --- lib/matplotlib/legend.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index ff13a1c5ccc5..4cf2f9d66169 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -259,7 +259,6 @@ def __init__(self, parent, handles, labels, else: self.prop = prop - self._fontsize = self.prop.get_size_in_points() self.texts = [] @@ -385,9 +384,8 @@ def __init__(self, parent, handles, labels, # init with null renderer self._init_legend_box(handles, labels, markerfirst) - # If shadow is activated also use framealpha if not + # If shadow is activated use framealpha if not # explicitly passed. See Issue 8943 - if framealpha is None: if shadow is True: self.framealpha = 1 From 538da8738e1c995e23373632410f22ab5abb0eb2 Mon Sep 17 00:00:00 2001 From: s0vereign Date: Fri, 4 Aug 2017 12:53:18 +0200 Subject: [PATCH 3/6] Fixed pep8 violations in test case --- lib/matplotlib/tests/test_legend.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_legend.py b/lib/matplotlib/tests/test_legend.py index 8b31e2c3a2ec..db397e9ab47c 100644 --- a/lib/matplotlib/tests/test_legend.py +++ b/lib/matplotlib/tests/test_legend.py @@ -362,8 +362,9 @@ def test_handler_numpoints(): def test_shadow_framealpha(): - '''Test if framealpha is activated when shadow is True and framealpha is not explicitly passed''' + # Test if framealpha is activated when shadow is True + # and framealpha is not explicitly passed''' fig, ax = plt.subplots() - ax.plot(range(100),label="test") + ax.plot(range(100), label="test") leg = ax.legend(shadow=True, facecolor='w') assert leg.framealpha == 1 From a030a8d538951ad0d622386d6ff7dba1af2c81e4 Mon Sep 17 00:00:00 2001 From: s0vereign Date: Sat, 5 Aug 2017 01:24:02 +0200 Subject: [PATCH 4/6] alpha of legend is now set with set_alpha method and thus changed the test to use the get_alpha method --- lib/matplotlib/legend.py | 4 ++-- lib/matplotlib/tests/test_legend.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index 4cf2f9d66169..a5481488cf59 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -387,8 +387,8 @@ def __init__(self, parent, handles, labels, # If shadow is activated use framealpha if not # explicitly passed. See Issue 8943 if framealpha is None: - if shadow is True: - self.framealpha = 1 + if shadow: + self.get_frame().set_alpha(1) else: self.get_frame().set_alpha(rcParams["legend.framealpha"]) else: diff --git a/lib/matplotlib/tests/test_legend.py b/lib/matplotlib/tests/test_legend.py index db397e9ab47c..978a59f602a3 100644 --- a/lib/matplotlib/tests/test_legend.py +++ b/lib/matplotlib/tests/test_legend.py @@ -367,4 +367,4 @@ def test_shadow_framealpha(): fig, ax = plt.subplots() ax.plot(range(100), label="test") leg = ax.legend(shadow=True, facecolor='w') - assert leg.framealpha == 1 + assert leg.get_frame().get_alpha() == 1 \ No newline at end of file From 569c4f5b93276868959288a221edcbc8d6a692c4 Mon Sep 17 00:00:00 2001 From: s0vereign Date: Wed, 9 Aug 2017 15:33:57 +0200 Subject: [PATCH 5/6] Added blank line in test_legend.py at EOF for pep8 compliance --- lib/matplotlib/tests/test_legend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_legend.py b/lib/matplotlib/tests/test_legend.py index 978a59f602a3..3b1f3e31bd07 100644 --- a/lib/matplotlib/tests/test_legend.py +++ b/lib/matplotlib/tests/test_legend.py @@ -367,4 +367,4 @@ def test_shadow_framealpha(): fig, ax = plt.subplots() ax.plot(range(100), label="test") leg = ax.legend(shadow=True, facecolor='w') - assert leg.get_frame().get_alpha() == 1 \ No newline at end of file + assert leg.get_frame().get_alpha() == 1 From 755d9c8ffd01bba14372b05373132cd810e5c800 Mon Sep 17 00:00:00 2001 From: s0vereign Date: Wed, 9 Aug 2017 15:43:54 +0200 Subject: [PATCH 6/6] Added lines to lib/matplotlib/axes/_axes.py to account for ignoring framealpha default value if shadow is activated. --- lib/matplotlib/axes/_axes.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index bddf37e018c2..a04d177b064a 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -429,6 +429,8 @@ def legend(self, *args, **kwargs): Control the alpha transparency of the legend's background. Default is ``None`` which will take the value from the ``legend.framealpha`` :data:`rcParam`. + If shadow is activated and framealpha is ``None`` the + default value is being ignored. facecolor : None or "inherit" or a color spec Control the legend's background color.