Skip to content

Commit 772d285

Browse files
authored
REF: Remove un-used attribute-pinning in plotting (#55944)
1 parent 2c23332 commit 772d285

File tree

3 files changed

+12
-32
lines changed

3 files changed

+12
-32
lines changed

pandas/plotting/_matplotlib/converter.py

+3-14
Original file line numberDiff line numberDiff line change
@@ -983,10 +983,7 @@ def __init__(
983983

984984
def _get_default_locs(self, vmin, vmax):
985985
"""Returns the default locations of ticks."""
986-
if self.plot_obj.date_axis_info is None:
987-
self.plot_obj.date_axis_info = self.finder(vmin, vmax, self.freq)
988-
989-
locator = self.plot_obj.date_axis_info
986+
locator = self.finder(vmin, vmax, self.freq)
990987

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

999996
vi = tuple(self.axis.get_view_interval())
1000-
if vi != self.plot_obj.view_interval:
1001-
self.plot_obj.date_axis_info = None
1002-
self.plot_obj.view_interval = vi
1003997
vmin, vmax = vi
1004998
if vmax < vmin:
1005999
vmin, vmax = vmax, vmin
@@ -1072,9 +1066,7 @@ def __init__(
10721066

10731067
def _set_default_format(self, vmin, vmax):
10741068
"""Returns the default ticks spacing."""
1075-
if self.plot_obj.date_axis_info is None:
1076-
self.plot_obj.date_axis_info = self.finder(vmin, vmax, self.freq)
1077-
info = self.plot_obj.date_axis_info
1069+
info = self.finder(vmin, vmax, self.freq)
10781070

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

10911083
self.locs = locs
10921084

1093-
(vmin, vmax) = vi = tuple(self.axis.get_view_interval())
1094-
if vi != self.plot_obj.view_interval:
1095-
self.plot_obj.date_axis_info = None
1096-
self.plot_obj.view_interval = vi
1085+
(vmin, vmax) = tuple(self.axis.get_view_interval())
10971086
if vmax < vmin:
10981087
(vmin, vmax) = (vmax, vmin)
10991088
self._set_default_format(vmin, vmax)

pandas/plotting/_matplotlib/core.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1589,12 +1589,12 @@ def _ts_plot(self, ax: Axes, x, data: Series, style=None, **kwds):
15891589
freq, data = maybe_resample(data, ax, kwds)
15901590

15911591
# Set ax with freq info
1592-
decorate_axes(ax, freq, kwds)
1592+
decorate_axes(ax, freq)
15931593
# digging deeper
15941594
if hasattr(ax, "left_ax"):
1595-
decorate_axes(ax.left_ax, freq, kwds)
1595+
decorate_axes(ax.left_ax, freq)
15961596
if hasattr(ax, "right_ax"):
1597-
decorate_axes(ax.right_ax, freq, kwds)
1597+
decorate_axes(ax.right_ax, freq)
15981598
# TODO #54485
15991599
ax._plot_data.append((data, self._kind, kwds)) # type: ignore[attr-defined]
16001600

pandas/plotting/_matplotlib/timeseries.py

+6-15
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ def _is_sup(f1: str, f2: str) -> bool:
111111

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

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

123123
if other_ax is not None:
124-
rlines, rlabels = _replot_ax(other_ax, freq, kwargs)
124+
rlines, rlabels = _replot_ax(other_ax, freq)
125125
lines.extend(rlines)
126126
labels.extend(rlabels)
127127

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

134134

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

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

143-
decorate_axes(ax, freq, kwargs)
143+
decorate_axes(ax, freq)
144144

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

166166

167-
def decorate_axes(ax: Axes, freq: BaseOffset, kwargs: dict[str, Any]) -> None:
167+
def decorate_axes(ax: Axes, freq: BaseOffset) -> None:
168168
"""Initialize axes for time-series plotting"""
169169
if not hasattr(ax, "_plot_data"):
170170
# TODO #54485
@@ -175,15 +175,6 @@ def decorate_axes(ax: Axes, freq: BaseOffset, kwargs: dict[str, Any]) -> None:
175175
xaxis = ax.get_xaxis()
176176
# TODO #54485
177177
xaxis.freq = freq # type: ignore[attr-defined]
178-
if not hasattr(ax, "legendlabels"):
179-
# TODO #54485
180-
ax.legendlabels = [kwargs.get("label", None)] # type: ignore[attr-defined]
181-
else:
182-
ax.legendlabels.append(kwargs.get("label", None))
183-
# TODO #54485
184-
ax.view_interval = None # type: ignore[attr-defined]
185-
# TODO #54485
186-
ax.date_axis_info = None # type: ignore[attr-defined]
187178

188179

189180
def _get_ax_freq(ax: Axes):

0 commit comments

Comments
 (0)