Skip to content

Commit 05eed69

Browse files
committed
TST: Test for issues pandas-dev#26186 and pandas-dev#11465
1 parent e734449 commit 05eed69

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

pandas/tests/plotting/test_frame.py

+34
Original file line numberDiff line numberDiff line change
@@ -3326,6 +3326,40 @@ def test_colors_of_columns_with_same_name(self):
33263326
for legend, line in zip(result.get_legend().legendHandles, result.lines):
33273327
assert legend.get_color() == line.get_color()
33283328

3329+
@pytest.mark.slow
3330+
@pytest.mark.parametrize("method", ["bar", "barh"])
3331+
def test_bar_ticklabel_consistence(self, method):
3332+
# Draw two consecutiv bar plot with consistent ticklabels
3333+
# GH: 26186
3334+
def get_main_axis(ax):
3335+
if method == "barh":
3336+
return ax.yaxis
3337+
elif method == "bar":
3338+
return ax.xaxis
3339+
3340+
data = {"A": 0, "B": 3, "C": -4}
3341+
df = pd.DataFrame.from_dict(data, orient="index", columns=["Value"])
3342+
ax = getattr(df.plot, method)()
3343+
ax.get_figure().canvas.draw()
3344+
xticklabels = [t.get_text() for t in get_main_axis(ax).get_ticklabels()]
3345+
label_positions_1 = dict(zip(xticklabels, get_main_axis(ax).get_ticklocs()))
3346+
df = df.sort_values("Value") * -2
3347+
ax = getattr(df.plot, method)(ax=ax, color="red")
3348+
ax.get_figure().canvas.draw()
3349+
xticklabels = [t.get_text() for t in get_main_axis(ax).get_ticklabels()]
3350+
label_positions_2 = dict(zip(xticklabels, get_main_axis(ax).get_ticklocs()))
3351+
assert label_positions_1 == label_positions_2
3352+
3353+
def test_bar_numeric(self):
3354+
# Bar plot with numeric index have tick location values equal to index
3355+
# values
3356+
# GH: 11465
3357+
index = np.arange(10, 20)
3358+
df = pd.DataFrame(np.random.rand(10), index=np.arange(10, 20))
3359+
ax = df.plot.bar()
3360+
ticklocs = ax.xaxis.get_ticklocs()
3361+
tm.assert_numpy_array_equal(ticklocs, index)
3362+
33293363

33303364
def _generate_4_axes_via_gridspec():
33313365
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)