Skip to content

Commit cb22f9b

Browse files
committed
fix: base logic and version doc
1 parent 37975eb commit cb22f9b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

doc/source/whatsnew/v2.2.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ Plotting
848848
^^^^^^^^
849849
- Bug in :meth:`DataFrame.plot.box` with ``vert=False`` and a Matplotlib ``Axes`` created with ``sharey=True`` (:issue:`54941`)
850850
- Bug in :meth:`DataFrame.plot.scatter` discarding string columns (:issue:`56142`)
851+
- Bug in :meth:`DataFrame.plot` where bar and line plots are not aligned on the x-axis (:issue:`56611`)
851852
- Bug in :meth:`Series.plot` when reusing an ``ax`` object failing to raise when a ``how`` keyword is passed (:issue:`55953`)
852853

853854
Groupby/resample/rolling

pandas/plotting/_matplotlib/core.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -1805,6 +1805,19 @@ 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
1809+
@final
1810+
def _is_usable_series(self) -> bool:
1811+
return self._is_series and not (
1812+
self.use_index and use_dynamic_x(self._get_ax(0), self.data)
1813+
)
1814+
1815+
def _set_tick_pos(self, data) -> np.ndarray:
1816+
if self._is_usable_series():
1817+
return np.array(self._get_xticks(), dtype=int)
1818+
else:
1819+
return np.arange(len(data))
1820+
18081821
def __init__(
18091822
self,
18101823
data,
@@ -1823,7 +1836,6 @@ def __init__(
18231836
self.bar_width = width
18241837
self._align = align
18251838
self._position = position
1826-
self.tick_pos = np.arange(len(data))
18271839

18281840
if is_list_like(bottom):
18291841
bottom = np.array(bottom)
@@ -1836,6 +1848,8 @@ def __init__(
18361848

18371849
MPLPlot.__init__(self, data, **kwargs)
18381850

1851+
self.tick_pos = self._set_tick_pos(data)
1852+
18391853
@cache_readonly
18401854
def ax_pos(self) -> np.ndarray:
18411855
return self.tick_pos - self.tickoffset

0 commit comments

Comments
 (0)