Skip to content

Commit 738ca94

Browse files
committed
TST: Test for issues pandas-dev#26186 and pandas-dev#11465
1 parent 02675e3 commit 738ca94

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

pandas/tests/plotting/test_frame.py

+37
Original file line numberDiff line numberDiff line change
@@ -3244,6 +3244,43 @@ def test_plot_no_numeric_data(self):
32443244
with pytest.raises(TypeError):
32453245
df.plot()
32463246

3247+
@pytest.mark.slow
3248+
@pytest.mark.parametrize('method', ['bar', 'barh'])
3249+
def test_bar_ticklabel_consistence(self, method):
3250+
# Draw two consecutiv bar plot with consistent ticklabels
3251+
# GH: 26186
3252+
def get_main_axis(ax):
3253+
if method == 'barh':
3254+
return ax.yaxis
3255+
elif method == 'bar':
3256+
return ax.xaxis
3257+
data = {"A": 0, "B": 3, "C": -4}
3258+
df = pd.DataFrame.from_dict(data, orient="index", columns=["Value"])
3259+
ax = getattr(df.plot, method)()
3260+
ax.get_figure().canvas.draw()
3261+
xticklabels = [t.get_text()
3262+
for t in get_main_axis(ax).get_ticklabels()]
3263+
label_positions_1 = dict(zip(xticklabels,
3264+
get_main_axis(ax).get_ticklocs()))
3265+
df = df.sort_values("Value") * - 2
3266+
ax = getattr(df.plot, method)(ax=ax, color="red")
3267+
ax.get_figure().canvas.draw()
3268+
xticklabels = [t.get_text()
3269+
for t in get_main_axis(ax).get_ticklabels()]
3270+
label_positions_2 = dict(zip(xticklabels,
3271+
get_main_axis(ax).get_ticklocs()))
3272+
assert label_positions_1 == label_positions_2
3273+
3274+
def test_bar_numeric(self):
3275+
# Bar plot with numeric index have tick location values equal to index
3276+
# values
3277+
# GH: 11465
3278+
index = np.arange(10, 20)
3279+
df = pd.DataFrame(np.random.rand(10), index=np.arange(10, 20))
3280+
ax = df.plot.bar()
3281+
ticklocs = ax.xaxis.get_ticklocs()
3282+
tm.assert_numpy_array_equal(ticklocs, index)
3283+
32473284

32483285
def _generate_4_axes_via_gridspec():
32493286
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)