@@ -1429,31 +1429,16 @@ def test_legend_text():
14291429 assert_allclose (leg_bboxes [1 ].bounds , leg_bboxes [0 ].bounds )
14301430
14311431
1432- def test_boxplot_legend ():
1433- # Test that boxplot legends handles are patches
1434- # and labels are generated from boxplot's labels parameter.
1435- fig , axs = plt .subplots ()
1436- A = 5 * np .random .rand (100 , 1 )
1437- B = 10 * np .random .rand (100 , 1 ) - 5
1438- C = 7 * np .random .rand (100 , 1 ) - 5
1439- labels = ['a' , 'b' , 'c' ]
1440-
1441- bp0 = axs .boxplot (A , positions = [0 ], patch_artist = True , labels = labels [0 ])
1442- bp1 = axs .boxplot (B , positions = [1 ], patch_artist = True , labels = labels [1 ])
1443- bp2 = axs .boxplot (C , positions = [2 ], patch_artist = True , labels = labels [2 ])
1444- # red, blue, green
1445- colors = [(1.0 , 0.0 , 0.0 , 1 ), (0.0 , 0.0 , 1.0 , 1 ), (0.0 , 0.5 , 0.0 , 1 )]
1446- box_list = [bp0 , bp1 , bp2 ]
1447- # Set colors to the boxes
1448- lbl_index = 0
1449- for b_plot , color in zip (box_list , colors ):
1450- for patch in b_plot ['boxes' ]:
1451- patch .set_color (color )
1452- lbl_index += 1
1453-
1454- legend = axs .legend ()
1455- for index , handle in enumerate (legend .legend_handles ):
1456- assert isinstance (handle , mpl .patches .Rectangle )
1457- assert handle .get_facecolor () == colors [index ]
1458- assert handle .get_edgecolor () == colors [index ]
1459- assert handle .get_label () == labels [index ]
1432+ def test_boxplot_labels ():
1433+ # Test that boxplot(..., labels=) sets the tick labels but not legend entries
1434+ # This is not consistent with other plot types but is the current behavior.
1435+ fig , ax = plt .subplots ()
1436+ np .random .seed (19680801 )
1437+ data = np .random .random ((10 , 3 ))
1438+ bp = ax .boxplot (data , labels = ['A' , 'B' , 'C' ])
1439+ # Check that labels set the tick labels ...
1440+ assert [l .get_text () for l in ax .get_xticklabels ()] == ['A' , 'B' , 'C' ]
1441+ # ... but not legend entries
1442+ handles , labels = ax .get_legend_handles_labels ()
1443+ assert len (handles ) == 0
1444+ assert len (labels ) == 0
0 commit comments