@@ -3444,24 +3444,34 @@ def test_xlabel_ylabel_dataframe_subplots(
3444
3444
@pytest .mark .parametrize ("method" , ["bar" , "barh" ])
3445
3445
def test_bar_ticklabel_consistence (self , method ):
3446
3446
# Draw two consecutiv bar plot with consistent ticklabels
3447
+ # The labels positions should not move between two drawing on the same axis
3447
3448
# GH: 26186
3448
3449
def get_main_axis (ax ):
3449
3450
if method == "barh" :
3450
3451
return ax .yaxis
3451
3452
elif method == "bar" :
3452
3453
return ax .xaxis
3453
3454
3455
+ # Plot the first bar plot
3454
3456
data = {"A" : 0 , "B" : 3 , "C" : - 4 }
3455
3457
df = pd .DataFrame .from_dict (data , orient = "index" , columns = ["Value" ])
3456
3458
ax = getattr (df .plot , method )()
3457
3459
ax .get_figure ().canvas .draw ()
3460
+
3461
+ # Retrieve the label positions for the first drawing
3458
3462
xticklabels = [t .get_text () for t in get_main_axis (ax ).get_ticklabels ()]
3459
3463
label_positions_1 = dict (zip (xticklabels , get_main_axis (ax ).get_ticklocs ()))
3464
+
3465
+ # Modify the dataframe order and values and plot on same axis
3460
3466
df = df .sort_values ("Value" ) * - 2
3461
3467
ax = getattr (df .plot , method )(ax = ax , color = "red" )
3462
3468
ax .get_figure ().canvas .draw ()
3469
+
3470
+ # Retrieve the label positions for the second drawing
3463
3471
xticklabels = [t .get_text () for t in get_main_axis (ax ).get_ticklabels ()]
3464
3472
label_positions_2 = dict (zip (xticklabels , get_main_axis (ax ).get_ticklocs ()))
3473
+
3474
+ # Assert that the label positions did not change between the plotting
3465
3475
assert label_positions_1 == label_positions_2
3466
3476
3467
3477
def test_bar_numeric (self ):
0 commit comments