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

Skip to content

Commit 8964e8a

Browse files
committed
Legend: Add test for reverse option
1 parent 5633cdf commit 8964e8a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/matplotlib/tests/test_legend.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,21 @@ def test_legend_remove():
294294
assert ax.get_legend() is None
295295

296296

297+
def test_reverse_legend():
298+
fig, ax = plt.subplots()
299+
x = [1, 2, 3]
300+
y = [1, 2, 3], [2, 3, 4], [3, 4, 5]
301+
labels = ["First label", "Second label", "Third label"]
302+
303+
ax.plot(x, y, label=labels)
304+
leg = ax.legend(reverse=True)
305+
actual_labels = []
306+
for text in leg.get_texts():
307+
actual_labels.append(text.get_text())
308+
excepted_labels = list(reversed(labels))
309+
assert actual_labels == excepted_labels
310+
311+
297312
class TestLegendFunction:
298313
# Tests the legend function on the Axes and pyplot.
299314
def test_legend_no_args(self):

0 commit comments

Comments
 (0)