@@ -7386,6 +7386,20 @@ def test_bar_label_location_vertical():
7386
7386
assert labels [1 ].get_va () == 'top'
7387
7387
7388
7388
7389
+ def test_bar_label_location_vertical_yinverted ():
7390
+ ax = plt .gca ()
7391
+ ax .invert_yaxis ()
7392
+ xs , heights = [1 , 2 ], [3 , - 4 ]
7393
+ rects = ax .bar (xs , heights )
7394
+ labels = ax .bar_label (rects )
7395
+ assert labels [0 ].xy == (xs [0 ], heights [0 ])
7396
+ assert labels [0 ].get_ha () == 'center'
7397
+ assert labels [0 ].get_va () == 'top'
7398
+ assert labels [1 ].xy == (xs [1 ], heights [1 ])
7399
+ assert labels [1 ].get_ha () == 'center'
7400
+ assert labels [1 ].get_va () == 'bottom'
7401
+
7402
+
7389
7403
def test_bar_label_location_horizontal ():
7390
7404
ax = plt .gca ()
7391
7405
ys , widths = [1 , 2 ], [3 , - 4 ]
@@ -7399,6 +7413,49 @@ def test_bar_label_location_horizontal():
7399
7413
assert labels [1 ].get_va () == 'center'
7400
7414
7401
7415
7416
+ def test_bar_label_location_horizontal_yinverted ():
7417
+ ax = plt .gca ()
7418
+ ax .invert_yaxis ()
7419
+ ys , widths = [1 , 2 ], [3 , - 4 ]
7420
+ rects = ax .barh (ys , widths )
7421
+ labels = ax .bar_label (rects )
7422
+ assert labels [0 ].xy == (widths [0 ], ys [0 ])
7423
+ assert labels [0 ].get_ha () == 'left'
7424
+ assert labels [0 ].get_va () == 'center'
7425
+ assert labels [1 ].xy == (widths [1 ], ys [1 ])
7426
+ assert labels [1 ].get_ha () == 'right'
7427
+ assert labels [1 ].get_va () == 'center'
7428
+
7429
+
7430
+ def test_bar_label_location_horizontal_xinverted ():
7431
+ ax = plt .gca ()
7432
+ ax .invert_xaxis ()
7433
+ ys , widths = [1 , 2 ], [3 , - 4 ]
7434
+ rects = ax .barh (ys , widths )
7435
+ labels = ax .bar_label (rects )
7436
+ assert labels [0 ].xy == (widths [0 ], ys [0 ])
7437
+ assert labels [0 ].get_ha () == 'right'
7438
+ assert labels [0 ].get_va () == 'center'
7439
+ assert labels [1 ].xy == (widths [1 ], ys [1 ])
7440
+ assert labels [1 ].get_ha () == 'left'
7441
+ assert labels [1 ].get_va () == 'center'
7442
+
7443
+
7444
+ def test_bar_label_location_horizontal_xyinverted ():
7445
+ ax = plt .gca ()
7446
+ ax .invert_xaxis ()
7447
+ ax .invert_yaxis ()
7448
+ ys , widths = [1 , 2 ], [3 , - 4 ]
7449
+ rects = ax .barh (ys , widths )
7450
+ labels = ax .bar_label (rects )
7451
+ assert labels [0 ].xy == (widths [0 ], ys [0 ])
7452
+ assert labels [0 ].get_ha () == 'right'
7453
+ assert labels [0 ].get_va () == 'center'
7454
+ assert labels [1 ].xy == (widths [1 ], ys [1 ])
7455
+ assert labels [1 ].get_ha () == 'left'
7456
+ assert labels [1 ].get_va () == 'center'
7457
+
7458
+
7402
7459
def test_bar_label_location_center ():
7403
7460
ax = plt .gca ()
7404
7461
ys , widths = [1 , 2 ], [3 , - 4 ]
@@ -7450,6 +7507,16 @@ def test_bar_label_nan_ydata():
7450
7507
assert labels [0 ].get_va () == 'bottom'
7451
7508
7452
7509
7510
+ def test_bar_label_nan_ydata_inverted ():
7511
+ ax = plt .gca ()
7512
+ ax .yaxis_inverted ()
7513
+ bars = ax .bar ([2 , 3 ], [np .nan , 1 ])
7514
+ labels = ax .bar_label (bars )
7515
+ assert [l .get_text () for l in labels ] == ['' , '1' ]
7516
+ assert labels [0 ].xy == (2 , 0 )
7517
+ assert labels [0 ].get_va () == 'bottom'
7518
+
7519
+
7453
7520
def test_patch_bounds (): # PR 19078
7454
7521
fig , ax = plt .subplots ()
7455
7522
ax .add_patch (mpatches .Wedge ((0 , - 1 ), 1.05 , 60 , 120 , 0.1 ))
0 commit comments