Skip to content

Commit ee183d7

Browse files
committed
Refactor time series plotting logic in Matplotlib backend.
Simplified `tick_pos` calculation by reusing helper methods and added a decorator to register pandas Matplotlib converters in the `_plot` method. This improves clarity and ensures proper integration with the pandas Matplotlib ecosystem.
1 parent 5fb6172 commit ee183d7

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pandas/plotting/_matplotlib/core.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,10 +1870,12 @@ def __init__(
18701870

18711871
MPLPlot.__init__(self, data, **kwargs)
18721872

1873-
if isinstance(data.index, ABCPeriodIndex):
1874-
self.ax.freq = data.index.freq
1873+
if self._is_ts_plot():
18751874
self.tick_pos = np.array(
1876-
PeriodConverter.convert(data.index._mpl_repr(), None, self.ax)
1875+
PeriodConverter.convert_from_freq(
1876+
self._get_xticks(),
1877+
data.index.freq,
1878+
)
18771879
)
18781880
else:
18791881
self.tick_pos = np.arange(len(data))
@@ -1907,6 +1909,7 @@ def lim_offset(self):
19071909

19081910
# error: Signature of "_plot" incompatible with supertype "MPLPlot"
19091911
@classmethod
1912+
@register_pandas_matplotlib_converters
19101913
def _plot( # type: ignore[override]
19111914
cls,
19121915
ax: Axes,

0 commit comments

Comments
 (0)