Skip to content

REF: Remove un-used attribute-pinning in plotting #55944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions pandas/plotting/_matplotlib/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,10 +983,7 @@ def __init__(

def _get_default_locs(self, vmin, vmax):
"""Returns the default locations of ticks."""
if self.plot_obj.date_axis_info is None:
self.plot_obj.date_axis_info = self.finder(vmin, vmax, self.freq)

locator = self.plot_obj.date_axis_info
locator = self.finder(vmin, vmax, self.freq)

if self.isminor:
return np.compress(locator["min"], locator["val"])
Expand All @@ -997,9 +994,6 @@ def __call__(self):
# axis calls Locator.set_axis inside set_m<xxxx>_formatter

vi = tuple(self.axis.get_view_interval())
if vi != self.plot_obj.view_interval:
self.plot_obj.date_axis_info = None
self.plot_obj.view_interval = vi
vmin, vmax = vi
if vmax < vmin:
vmin, vmax = vmax, vmin
Expand Down Expand Up @@ -1072,9 +1066,7 @@ def __init__(

def _set_default_format(self, vmin, vmax):
"""Returns the default ticks spacing."""
if self.plot_obj.date_axis_info is None:
self.plot_obj.date_axis_info = self.finder(vmin, vmax, self.freq)
info = self.plot_obj.date_axis_info
info = self.finder(vmin, vmax, self.freq)

if self.isminor:
format = np.compress(info["min"] & np.logical_not(info["maj"]), info)
Expand All @@ -1090,10 +1082,7 @@ def set_locs(self, locs) -> None:

self.locs = locs

(vmin, vmax) = vi = tuple(self.axis.get_view_interval())
if vi != self.plot_obj.view_interval:
self.plot_obj.date_axis_info = None
self.plot_obj.view_interval = vi
(vmin, vmax) = tuple(self.axis.get_view_interval())
if vmax < vmin:
(vmin, vmax) = (vmax, vmin)
self._set_default_format(vmin, vmax)
Expand Down
6 changes: 3 additions & 3 deletions pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1590,12 +1590,12 @@ def _ts_plot(self, ax: Axes, x, data: Series, style=None, **kwds):
freq, data = maybe_resample(data, ax, kwds)

# Set ax with freq info
decorate_axes(ax, freq, kwds)
decorate_axes(ax, freq)
# digging deeper
if hasattr(ax, "left_ax"):
decorate_axes(ax.left_ax, freq, kwds)
decorate_axes(ax.left_ax, freq)
if hasattr(ax, "right_ax"):
decorate_axes(ax.right_ax, freq, kwds)
decorate_axes(ax.right_ax, freq)
# TODO #54485
ax._plot_data.append((data, self._kind, kwds)) # type: ignore[attr-defined]

Expand Down
21 changes: 6 additions & 15 deletions pandas/plotting/_matplotlib/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def _is_sup(f1: str, f2: str) -> bool:

def _upsample_others(ax: Axes, freq: BaseOffset, kwargs: dict[str, Any]) -> None:
legend = ax.get_legend()
lines, labels = _replot_ax(ax, freq, kwargs)
_replot_ax(ax, freq, kwargs)
lines, labels = _replot_ax(ax, freq)
_replot_ax(ax, freq)

other_ax = None
if hasattr(ax, "left_ax"):
Expand All @@ -121,7 +121,7 @@ def _upsample_others(ax: Axes, freq: BaseOffset, kwargs: dict[str, Any]) -> None
other_ax = ax.right_ax

if other_ax is not None:
rlines, rlabels = _replot_ax(other_ax, freq, kwargs)
rlines, rlabels = _replot_ax(other_ax, freq)
lines.extend(rlines)
labels.extend(rlabels)

Expand All @@ -132,15 +132,15 @@ def _upsample_others(ax: Axes, freq: BaseOffset, kwargs: dict[str, Any]) -> None
ax.legend(lines, labels, loc="best", title=title)


def _replot_ax(ax: Axes, freq: BaseOffset, kwargs: dict[str, Any]):
def _replot_ax(ax: Axes, freq: BaseOffset):
data = getattr(ax, "_plot_data", None)

# clear current axes and data
# TODO #54485
ax._plot_data = [] # type: ignore[attr-defined]
ax.clear()

decorate_axes(ax, freq, kwargs)
decorate_axes(ax, freq)

lines = []
labels = []
Expand All @@ -164,7 +164,7 @@ def _replot_ax(ax: Axes, freq: BaseOffset, kwargs: dict[str, Any]):
return lines, labels


def decorate_axes(ax: Axes, freq: BaseOffset, kwargs: dict[str, Any]) -> None:
def decorate_axes(ax: Axes, freq: BaseOffset) -> None:
"""Initialize axes for time-series plotting"""
if not hasattr(ax, "_plot_data"):
# TODO #54485
Expand All @@ -175,15 +175,6 @@ def decorate_axes(ax: Axes, freq: BaseOffset, kwargs: dict[str, Any]) -> None:
xaxis = ax.get_xaxis()
# TODO #54485
xaxis.freq = freq # type: ignore[attr-defined]
if not hasattr(ax, "legendlabels"):
# TODO #54485
ax.legendlabels = [kwargs.get("label", None)] # type: ignore[attr-defined]
else:
ax.legendlabels.append(kwargs.get("label", None))
# TODO #54485
ax.view_interval = None # type: ignore[attr-defined]
# TODO #54485
ax.date_axis_info = None # type: ignore[attr-defined]


def _get_ax_freq(ax: Axes):
Expand Down