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

Skip to content

Commit 169c961

Browse files
committed
Add test to close legend issue
1 parent 1b2a3c9 commit 169c961

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/matplotlib/tests/test_legend.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,3 +910,20 @@ def test_setting_alpha_keeps_polycollection_color():
910910
patch.set_alpha(0.5)
911911
assert patch.get_facecolor()[:3] == tuple(pc.get_facecolor()[0][:3])
912912
assert patch.get_edgecolor()[:3] == tuple(pc.get_edgecolor()[0][:3])
913+
914+
915+
def test_legend_markers_from_line2d():
916+
# Test that markers can be copied for legend lines (#17960)
917+
_markers = ['.', '*', 'v']
918+
fig, ax = plt.subplots()
919+
lines = [mlines.Line2D([0], [0], ls='None', marker=mark)
920+
for mark in _markers]
921+
labels = ["foo", "bar", "xyzzy"]
922+
markers = [line.get_marker() for line in lines]
923+
legend = ax.legend(lines, labels)
924+
925+
new_markers = [line.get_marker() for line in legend.get_lines()]
926+
new_labels = [text.get_text() for text in legend.get_texts()]
927+
928+
assert markers == new_markers == _markers
929+
assert labels == new_labels

0 commit comments

Comments
 (0)