24
24
from pandas .tseries .frequencies import get_period_alias , is_subperiod , is_superperiod
25
25
26
26
if TYPE_CHECKING :
27
- from pandas import Index , Series # noqa:F401
27
+ from matplotlib . axes import Axes
28
28
29
+ from pandas import Index , Series # noqa:F401
29
30
30
31
# ---------------------------------------------------------------------
31
32
# Plotting functions and monkey patches
32
33
33
34
34
- def _maybe_resample (series : "Series" , ax , kwargs ):
35
+ def _maybe_resample (series : "Series" , ax : "Axes" , kwargs ):
35
36
# resample against axes freq if necessary
36
37
freq , ax_freq = _get_freq (ax , series )
37
38
@@ -74,7 +75,7 @@ def _is_sup(f1: str, f2: str) -> bool:
74
75
)
75
76
76
77
77
- def _upsample_others (ax , freq , kwargs ):
78
+ def _upsample_others (ax : "Axes" , freq , kwargs ):
78
79
legend = ax .get_legend ()
79
80
lines , labels = _replot_ax (ax , freq , kwargs )
80
81
_replot_ax (ax , freq , kwargs )
@@ -97,7 +98,7 @@ def _upsample_others(ax, freq, kwargs):
97
98
ax .legend (lines , labels , loc = "best" , title = title )
98
99
99
100
100
- def _replot_ax (ax , freq , kwargs ):
101
+ def _replot_ax (ax : "Axes" , freq , kwargs ):
101
102
data = getattr (ax , "_plot_data" , None )
102
103
103
104
# clear current axes and data
@@ -127,7 +128,7 @@ def _replot_ax(ax, freq, kwargs):
127
128
return lines , labels
128
129
129
130
130
- def _decorate_axes (ax , freq , kwargs ):
131
+ def _decorate_axes (ax : "Axes" , freq , kwargs ):
131
132
"""Initialize axes for time-series plotting"""
132
133
if not hasattr (ax , "_plot_data" ):
133
134
ax ._plot_data = []
@@ -143,7 +144,7 @@ def _decorate_axes(ax, freq, kwargs):
143
144
ax .date_axis_info = None
144
145
145
146
146
- def _get_ax_freq (ax ):
147
+ def _get_ax_freq (ax : "Axes" ):
147
148
"""
148
149
Get the freq attribute of the ax object if set.
149
150
Also checks shared axes (eg when using secondary yaxis, sharex=True
@@ -174,7 +175,7 @@ def _get_period_alias(freq) -> Optional[str]:
174
175
return freq
175
176
176
177
177
- def _get_freq (ax , series : "Series" ):
178
+ def _get_freq (ax : "Axes" , series : "Series" ):
178
179
# get frequency from data
179
180
freq = getattr (series .index , "freq" , None )
180
181
if freq is None :
@@ -192,7 +193,7 @@ def _get_freq(ax, series: "Series"):
192
193
return freq , ax_freq
193
194
194
195
195
- def _use_dynamic_x (ax , data : " FrameOrSeriesUnion" ) -> bool :
196
+ def _use_dynamic_x (ax : "Axes" , data : FrameOrSeriesUnion ) -> bool :
196
197
freq = _get_index_freq (data .index )
197
198
ax_freq = _get_ax_freq (ax )
198
199
@@ -234,7 +235,7 @@ def _get_index_freq(index: "Index") -> Optional[BaseOffset]:
234
235
return freq
235
236
236
237
237
- def _maybe_convert_index (ax , data ):
238
+ def _maybe_convert_index (ax : "Axes" , data ):
238
239
# tsplot converts automatically, but don't want to convert index
239
240
# over and over for DataFrames
240
241
if isinstance (data .index , (ABCDatetimeIndex , ABCPeriodIndex )):
@@ -264,7 +265,7 @@ def _maybe_convert_index(ax, data):
264
265
# Do we need the rest for convenience?
265
266
266
267
267
- def _format_coord (freq , t , y ):
268
+ def _format_coord (freq , t , y ) -> str :
268
269
time_period = Period (ordinal = int (t ), freq = freq )
269
270
return f"t = { time_period } y = { y :8f} "
270
271
0 commit comments