Skip to content

Commit a28db9c

Browse files
committed
TST: Improve test explanation
1 parent c19ef4b commit a28db9c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pandas/tests/plotting/test_frame.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,24 +3444,34 @@ def test_xlabel_ylabel_dataframe_subplots(
34443444
@pytest.mark.parametrize("method", ["bar", "barh"])
34453445
def test_bar_ticklabel_consistence(self, method):
34463446
# Draw two consecutiv bar plot with consistent ticklabels
3447+
# The labels positions should not move between two drawing on the same axis
34473448
# GH: 26186
34483449
def get_main_axis(ax):
34493450
if method == "barh":
34503451
return ax.yaxis
34513452
elif method == "bar":
34523453
return ax.xaxis
34533454

3455+
# Plot the first bar plot
34543456
data = {"A": 0, "B": 3, "C": -4}
34553457
df = pd.DataFrame.from_dict(data, orient="index", columns=["Value"])
34563458
ax = getattr(df.plot, method)()
34573459
ax.get_figure().canvas.draw()
3460+
3461+
# Retrieve the label positions for the first drawing
34583462
xticklabels = [t.get_text() for t in get_main_axis(ax).get_ticklabels()]
34593463
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
34603466
df = df.sort_values("Value") * -2
34613467
ax = getattr(df.plot, method)(ax=ax, color="red")
34623468
ax.get_figure().canvas.draw()
3469+
3470+
# Retrieve the label positions for the second drawing
34633471
xticklabels = [t.get_text() for t in get_main_axis(ax).get_ticklabels()]
34643472
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
34653475
assert label_positions_1 == label_positions_2
34663476

34673477
def test_bar_numeric(self):

0 commit comments

Comments
 (0)