Skip to content

Commit

Permalink
TST: Test for issues pandas-dev#26186 and pandas-dev#11465
Browse files Browse the repository at this point in the history
  • Loading branch information
nrebena committed Jun 17, 2020
1 parent 72aed3e commit 2377a6a
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pandas/tests/plotting/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3363,6 +3363,40 @@ def test_colors_of_columns_with_same_name(self):
for legend, line in zip(result.get_legend().legendHandles, result.lines):
assert legend.get_color() == line.get_color()

@pytest.mark.slow
@pytest.mark.parametrize("method", ["bar", "barh"])
def test_bar_ticklabel_consistence(self, method):
# Draw two consecutiv bar plot with consistent ticklabels
# GH: 26186
def get_main_axis(ax):
if method == "barh":
return ax.yaxis
elif method == "bar":
return ax.xaxis

data = {"A": 0, "B": 3, "C": -4}
df = pd.DataFrame.from_dict(data, orient="index", columns=["Value"])
ax = getattr(df.plot, method)()
ax.get_figure().canvas.draw()
xticklabels = [t.get_text() for t in get_main_axis(ax).get_ticklabels()]
label_positions_1 = dict(zip(xticklabels, get_main_axis(ax).get_ticklocs()))
df = df.sort_values("Value") * -2
ax = getattr(df.plot, method)(ax=ax, color="red")
ax.get_figure().canvas.draw()
xticklabels = [t.get_text() for t in get_main_axis(ax).get_ticklabels()]
label_positions_2 = dict(zip(xticklabels, get_main_axis(ax).get_ticklocs()))
assert label_positions_1 == label_positions_2

def test_bar_numeric(self):
# Bar plot with numeric index have tick location values equal to index
# values
# GH: 11465
index = np.arange(10, 20)
df = pd.DataFrame(np.random.rand(10), index=np.arange(10, 20))
ax = df.plot.bar()
ticklocs = ax.xaxis.get_ticklocs()
tm.assert_numpy_array_equal(ticklocs, index)


def _generate_4_axes_via_gridspec():
import matplotlib.pyplot as plt
Expand Down

0 comments on commit 2377a6a

Please sign in to comment.