Skip to content

Commit dc9042a

Browse files
committed
feat: added test to check barplot axes
1 parent 326f1a2 commit dc9042a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

pandas/plotting/_matplotlib/core.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1805,7 +1805,7 @@ def _kind(self) -> Literal["bar", "barh"]:
18051805
def orientation(self) -> PlottingOrientation:
18061806
return "vertical"
18071807

1808-
# GH56611 checks similar to LinePlot's _is_ts_plot and _use_dynamic_x
1808+
# GH56460 checks similar to LinePlot's _is_ts_plot and _use_dynamic_x
18091809
@final
18101810
def _is_ts_plot(self, data) -> bool:
18111811
return self.use_index and use_dynamic_x(self._get_ax(0), data)

pandas/tests/plotting/test_series.py

+19
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,25 @@ def test_series_none_color(self):
974974
expected = _unpack_cycler(mpl.pyplot.rcParams)[:1]
975975
_check_colors(ax.get_lines(), linecolors=expected)
976976

977+
@pytest.mark.parametrize(
978+
"plot_data",
979+
[
980+
(
981+
{
982+
"bars": {-1: 0.5, 0: 1.0, 1: 3.0, 2: 3.5, 3: 1.5},
983+
"pct": {-1: 1.0, 0: 2.0, 1: 3.0, 2: 4.0, 3: 8.0},
984+
}
985+
)
986+
],
987+
)
988+
def test_bar_plot_x_axis(self, plot_data):
989+
df = DataFrame(plot_data)
990+
ax_bar = df["bars"].plot(kind="bar")
991+
df["pct"].plot(kind="line")
992+
actual_bar_x = [bar.get_x() + bar.get_width() / 2.0 for bar in ax_bar.patches]
993+
expected_x = [-1, 0, 1, 2, 3]
994+
assert actual_bar_x == expected_x
995+
977996
@pytest.mark.slow
978997
def test_plot_no_warning(self, ts):
979998
# GH 55138

0 commit comments

Comments
 (0)