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

Skip to content

Commit 7da7795

Browse files
committed
Add test adding legend to subfigure
1 parent b5701e1 commit 7da7795

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/matplotlib/tests/test_legend.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,3 +871,12 @@ def test_handlerline2d():
871871
handles = [mlines.Line2D([0], [0], marker="v")]
872872
leg = ax.legend(handles, ["Aardvark"], numpoints=1)
873873
assert handles[0].get_marker() == leg.legendHandles[0].get_marker()
874+
875+
876+
def test_subfigure_legend():
877+
# Test that legend can be added to subfigure (#20723)
878+
subfig = plt.figure().subfigures()
879+
ax = subfig.subplots()
880+
ax.plot([0, 1], [0, 1], label="line")
881+
leg = subfig.legend()
882+
assert leg.figure is subfig

0 commit comments

Comments
 (0)