Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 363e25f

Browse files
authored
Merge pull request matplotlib#8988 from s0vereign/shadowfix
FIX: If Legend shadow=True set framealpha=1 by default
2 parents cc9284e + 755d9c8 commit 363e25f

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ def legend(self, *args, **kwargs):
428428
Control the alpha transparency of the legend's background.
429429
Default is ``None`` which will take the value from the
430430
``legend.framealpha`` :data:`rcParam<matplotlib.rcParams>`.
431+
If shadow is activated and framealpha is ``None`` the
432+
default value is being ignored.
431433
432434
facecolor : None or "inherit" or a color spec
433435
Control the legend's background color.

lib/matplotlib/legend.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,13 @@ def __init__(self, parent, handles, labels,
384384
# init with null renderer
385385
self._init_legend_box(handles, labels, markerfirst)
386386

387+
# If shadow is activated use framealpha if not
388+
# explicitly passed. See Issue 8943
387389
if framealpha is None:
388-
self.get_frame().set_alpha(rcParams["legend.framealpha"])
390+
if shadow:
391+
self.get_frame().set_alpha(1)
392+
else:
393+
self.get_frame().set_alpha(rcParams["legend.framealpha"])
389394
else:
390395
self.get_frame().set_alpha(framealpha)
391396

lib/matplotlib/tests/test_legend.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,3 +359,12 @@ def test_handler_numpoints():
359359
fig, ax = plt.subplots()
360360
ax.plot(range(5), label='test')
361361
ax.legend(numpoints=0.5)
362+
363+
364+
def test_shadow_framealpha():
365+
# Test if framealpha is activated when shadow is True
366+
# and framealpha is not explicitly passed'''
367+
fig, ax = plt.subplots()
368+
ax.plot(range(100), label="test")
369+
leg = ax.legend(shadow=True, facecolor='w')
370+
assert leg.get_frame().get_alpha() == 1

0 commit comments

Comments
 (0)