Skip to content

Commit 3699e11

Browse files
committed
TST: Test for issues pandas-dev#26186 and pandas-dev#11465
1 parent 2067d7e commit 3699e11

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

pandas/tests/plotting/test_frame.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3440,6 +3440,40 @@ def test_xlabel_ylabel_dataframe_subplots(
34403440
assert all(ax.get_ylabel() == str(new_label) for ax in axes)
34413441
assert all(ax.get_xlabel() == str(new_label) for ax in axes)
34423442

3443+
@pytest.mark.slow
3444+
@pytest.mark.parametrize("method", ["bar", "barh"])
3445+
def test_bar_ticklabel_consistence(self, method):
3446+
# Draw two consecutiv bar plot with consistent ticklabels
3447+
# GH: 26186
3448+
def get_main_axis(ax):
3449+
if method == "barh":
3450+
return ax.yaxis
3451+
elif method == "bar":
3452+
return ax.xaxis
3453+
3454+
data = {"A": 0, "B": 3, "C": -4}
3455+
df = pd.DataFrame.from_dict(data, orient="index", columns=["Value"])
3456+
ax = getattr(df.plot, method)()
3457+
ax.get_figure().canvas.draw()
3458+
xticklabels = [t.get_text() for t in get_main_axis(ax).get_ticklabels()]
3459+
label_positions_1 = dict(zip(xticklabels, get_main_axis(ax).get_ticklocs()))
3460+
df = df.sort_values("Value") * -2
3461+
ax = getattr(df.plot, method)(ax=ax, color="red")
3462+
ax.get_figure().canvas.draw()
3463+
xticklabels = [t.get_text() for t in get_main_axis(ax).get_ticklabels()]
3464+
label_positions_2 = dict(zip(xticklabels, get_main_axis(ax).get_ticklocs()))
3465+
assert label_positions_1 == label_positions_2
3466+
3467+
def test_bar_numeric(self):
3468+
# Bar plot with numeric index have tick location values equal to index
3469+
# values
3470+
# GH: 11465
3471+
index = np.arange(10, 20)
3472+
df = pd.DataFrame(np.random.rand(10), index=np.arange(10, 20))
3473+
ax = df.plot.bar()
3474+
ticklocs = ax.xaxis.get_ticklocs()
3475+
tm.assert_numpy_array_equal(ticklocs, index)
3476+
34433477

34443478
def _generate_4_axes_via_gridspec():
34453479
import matplotlib as mpl

0 commit comments

Comments
 (0)