File tree 2 files changed +16
-1
lines changed
pandas/plotting/_matplotlib
2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -848,6 +848,7 @@ Plotting
848
848
^^^^^^^^
849
849
- Bug in :meth: `DataFrame.plot.box ` with ``vert=False `` and a Matplotlib ``Axes `` created with ``sharey=True `` (:issue: `54941 `)
850
850
- 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 `)
851
852
- Bug in :meth: `Series.plot ` when reusing an ``ax `` object failing to raise when a ``how `` keyword is passed (:issue: `55953 `)
852
853
853
854
Groupby/resample/rolling
Original file line number Diff line number Diff line change @@ -1805,6 +1805,19 @@ def _kind(self) -> Literal["bar", "barh"]:
1805
1805
def orientation (self ) -> PlottingOrientation :
1806
1806
return "vertical"
1807
1807
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
+
1808
1821
def __init__ (
1809
1822
self ,
1810
1823
data ,
@@ -1823,7 +1836,6 @@ def __init__(
1823
1836
self .bar_width = width
1824
1837
self ._align = align
1825
1838
self ._position = position
1826
- self .tick_pos = np .arange (len (data ))
1827
1839
1828
1840
if is_list_like (bottom ):
1829
1841
bottom = np .array (bottom )
@@ -1836,6 +1848,8 @@ def __init__(
1836
1848
1837
1849
MPLPlot .__init__ (self , data , ** kwargs )
1838
1850
1851
+ self .tick_pos = self ._set_tick_pos (data )
1852
+
1839
1853
@cache_readonly
1840
1854
def ax_pos (self ) -> np .ndarray :
1841
1855
return self .tick_pos - self .tickoffset
You can’t perform that action at this time.
0 commit comments