@@ -294,7 +294,8 @@ def test_legend_remove():
294
294
assert ax .get_legend () is None
295
295
296
296
297
- def test_reverse_legend ():
297
+ def test_reverse_legend_handles_and_labels ():
298
+ """Check that the legend handles and labels are reversed."""
298
299
fig , ax = plt .subplots ()
299
300
x = 1
300
301
y = 1
@@ -307,8 +308,22 @@ def test_reverse_legend():
307
308
leg = ax .legend (reverse = True )
308
309
actual_labels = [t .get_text () for t in leg .get_texts ()]
309
310
actual_markers = [h .get_marker () for h in leg .legend_handles ]
310
- assert (actual_labels , actual_markers ) == (list (reversed (labels )),
311
- (list (reversed (markers ))))
311
+ assert actual_labels == list (reversed (labels ))
312
+ assert actual_markers == list (reversed (markers ))
313
+
314
+
315
+ @check_figures_equal (extensions = ["png" ])
316
+ def test_reverse_legend_display (fig_test , fig_ref ):
317
+ """Check that the rendered legend entries are reversed"""
318
+ ax = fig_test .subplots ()
319
+ ax .plot ([1 ], 'ro' , label = "first" )
320
+ ax .plot ([2 ], 'bx' , label = "second" )
321
+ ax .legend (reverse = True )
322
+
323
+ ax = fig_ref .subplots ()
324
+ ax .plot ([2 ], 'bx' , label = "second" )
325
+ ax .plot ([1 ], 'ro' , label = "first" )
326
+ ax .legend ()
312
327
313
328
314
329
class TestLegendFunction :
0 commit comments