Skip to content

Commit 16762b6

Browse files
committed
Refactor time series handling in matplotlib plotting.
Move `x_compat` logic and time series helper methods from `LinePlot` to `MPLPlot` for better reusability and maintainability. This simplifies the `LinePlot` class and centralizes common functionality.
1 parent 218871d commit 16762b6

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

pandas/plotting/_matplotlib/core.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,21 @@ def __init__(
291291

292292
self.data = self._ensure_frame(self.data)
293293

294+
from pandas.plotting import plot_params
295+
296+
self.x_compat = plot_params["x_compat"]
297+
if "x_compat" in self.kwds:
298+
self.x_compat = bool(self.kwds.pop("x_compat"))
299+
300+
@final
301+
def _is_ts_plot(self) -> bool:
302+
# this is slightly deceptive
303+
return not self.x_compat and self.use_index and self._use_dynamic_x()
304+
305+
@final
306+
def _use_dynamic_x(self) -> bool:
307+
return use_dynamic_x(self._get_ax(0), self.data)
308+
294309
@final
295310
@staticmethod
296311
def _validate_sharex(sharex: bool | None, ax, by) -> bool:
@@ -1523,23 +1538,9 @@ def _kind(self) -> Literal["line", "area", "hist", "kde", "box"]:
15231538
return "line"
15241539

15251540
def __init__(self, data, **kwargs) -> None:
1526-
from pandas.plotting import plot_params
1527-
15281541
MPLPlot.__init__(self, data, **kwargs)
15291542
if self.stacked:
15301543
self.data = self.data.fillna(value=0)
1531-
self.x_compat = plot_params["x_compat"]
1532-
if "x_compat" in self.kwds:
1533-
self.x_compat = bool(self.kwds.pop("x_compat"))
1534-
1535-
@final
1536-
def _is_ts_plot(self) -> bool:
1537-
# this is slightly deceptive
1538-
return not self.x_compat and self.use_index and self._use_dynamic_x()
1539-
1540-
@final
1541-
def _use_dynamic_x(self) -> bool:
1542-
return use_dynamic_x(self._get_ax(0), self.data)
15431544

15441545
def _make_plot(self, fig: Figure) -> None:
15451546
if self._is_ts_plot():

0 commit comments

Comments
 (0)