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<matplotlib.rcParams>`. + 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. diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index e649741162cc..a5481488cf59 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -384,8 +384,13 @@ def __init__(self, parent, handles, labels, # init with null renderer self._init_legend_box(handles, labels, markerfirst) + # If shadow is activated use framealpha if not + # explicitly passed. See Issue 8943 if framealpha is None: - self.get_frame().set_alpha(rcParams["legend.framealpha"]) + if shadow: + self.get_frame().set_alpha(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..3b1f3e31bd07 100644 --- a/lib/matplotlib/tests/test_legend.py +++ b/lib/matplotlib/tests/test_legend.py @@ -359,3 +359,12 @@ 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.get_frame().get_alpha() == 1