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

Skip to content

Commit 60417e3

Browse files
committed
Added test for legend.shadow argument types
1 parent 3137016 commit 60417e3

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/matplotlib/tests/test_legend.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,30 @@ def test_empty_bar_chart_with_legend():
532532
plt.legend()
533533

534534

535+
def test_shadow_argument_types():
536+
# Test that different arguments for shadow work as expected
537+
fig, ax = plt.subplots()
538+
ax.plot([1, 2, 3], label='test')
539+
shadows = [True, False, 'red', (0.1, 0.2, 0.5), 'tab:cyan', False]
540+
541+
legends = (ax.legend(loc='upper left', shadow=True), # True
542+
ax.legend(loc='upper right', shadow=False), # False
543+
ax.legend(loc='center left', shadow='red'), # Color string
544+
ax.legend(loc='center right', shadow=(0.1, 0.2, 0.5)), # Color tuple
545+
ax.legend(loc='lower left', shadow='tab:cyan') # Color tab
546+
)
547+
for l in legends:
548+
ax.add_artist(l)
549+
ax.legend(loc='lower right') # default
550+
551+
legends = [c for c in ax.get_children() if isinstance(c, mpl.legend.Legend)]
552+
assert len(legends) == len(shadows)
553+
for i in range(len(legends)):
554+
assert legends[i].shadow == shadows[i]
555+
556+
with pytest.raises(ValueError, match="color or bool"):
557+
ax.legend(loc="upper left", shadow="aardvark") # Bad argument
558+
535559
def test_shadow_framealpha():
536560
# Test if framealpha is activated when shadow is True
537561
# and framealpha is not explicitly passed'''

0 commit comments

Comments
 (0)