direl-ts-tool-kit 0.9.0__py3-none-any.whl → 0.10.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- direl_ts_tool_kit/plot/plot_ts.py +131 -0
- {direl_ts_tool_kit-0.9.0.dist-info → direl_ts_tool_kit-0.10.0.dist-info}/METADATA +1 -1
- direl_ts_tool_kit-0.10.0.dist-info/RECORD +11 -0
- direl_ts_tool_kit-0.9.0.dist-info/RECORD +0 -11
- {direl_ts_tool_kit-0.9.0.dist-info → direl_ts_tool_kit-0.10.0.dist-info}/WHEEL +0 -0
- {direl_ts_tool_kit-0.9.0.dist-info → direl_ts_tool_kit-0.10.0.dist-info}/licenses/LICENCE +0 -0
- {direl_ts_tool_kit-0.9.0.dist-info → direl_ts_tool_kit-0.10.0.dist-info}/top_level.txt +0 -0
|
@@ -123,6 +123,137 @@ def plot_time_series(
|
|
|
123
123
|
return fig
|
|
124
124
|
|
|
125
125
|
|
|
126
|
+
def plot_forecast(
|
|
127
|
+
df_hist,
|
|
128
|
+
df_ts,
|
|
129
|
+
variable,
|
|
130
|
+
units="",
|
|
131
|
+
color_hist="BLUE_LINES",
|
|
132
|
+
color_forecast="RED_LINES",
|
|
133
|
+
time_unit="Year",
|
|
134
|
+
rot=90,
|
|
135
|
+
auto_format_label=True,
|
|
136
|
+
):
|
|
137
|
+
"""
|
|
138
|
+
Plots historical data alongside a forecast with a shaded confidence interval.
|
|
139
|
+
|
|
140
|
+
This function combines a historical time series with a forecast period,
|
|
141
|
+
automatically formatting axes, labels, and applying professional styling.
|
|
142
|
+
It expects the forecast DataFrame to include lower and upper bound columns
|
|
143
|
+
named '{variable}_lower' and '{variable}_upper'.
|
|
144
|
+
|
|
145
|
+
Parameters
|
|
146
|
+
----------
|
|
147
|
+
df_hist : pd.DataFrame
|
|
148
|
+
The DataFrame containing historical data. Must have a DatetimeIndex.
|
|
149
|
+
df_ts : pd.DataFrame
|
|
150
|
+
The DataFrame containing the forecast data and confidence intervals.
|
|
151
|
+
Must have a DatetimeIndex.
|
|
152
|
+
variable : str
|
|
153
|
+
The name of the column to plot in both DataFrames.
|
|
154
|
+
units : str, optional
|
|
155
|
+
Units to display next to the variable name on the y-axis (e.g., 'USD').
|
|
156
|
+
Defaults to "".
|
|
157
|
+
color : str, optional
|
|
158
|
+
Key corresponding to the line color for the forecast in the
|
|
159
|
+
global 'paper_colors' dictionary. Defaults to "BLUE_LINES".
|
|
160
|
+
time_unit : str, optional
|
|
161
|
+
The time granularity of the data to define x-axis tick locators.
|
|
162
|
+
Options: 'Year', 'Month', 'Weekday', 'Day' or 'Hour'. Defaults to "Year".
|
|
163
|
+
rot : int, optional
|
|
164
|
+
Rotation angle for the x-axis tick labels. Defaults to 90.
|
|
165
|
+
auto_format_label : bool, optional
|
|
166
|
+
If True, automatically formats the Y-axis label into Title Case.
|
|
167
|
+
Defaults to True.
|
|
168
|
+
|
|
169
|
+
Returns
|
|
170
|
+
-------
|
|
171
|
+
matplotlib.figure.Figure
|
|
172
|
+
The generated matplotlib figure object.
|
|
173
|
+
|
|
174
|
+
Notes
|
|
175
|
+
-----
|
|
176
|
+
The confidence interval is shaded using 'GRAY_BARS' from the paper_colors
|
|
177
|
+
palette with a transparency of 0.3.
|
|
178
|
+
"""
|
|
179
|
+
|
|
180
|
+
fig, ax = plt.subplots()
|
|
181
|
+
|
|
182
|
+
ax.plot(
|
|
183
|
+
df_hist.index,
|
|
184
|
+
df_hist[variable],
|
|
185
|
+
linewidth=2,
|
|
186
|
+
color=paper_colors[color_hist],
|
|
187
|
+
label="Historical",
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
ax.plot(
|
|
191
|
+
df_ts.index,
|
|
192
|
+
df_ts[variable],
|
|
193
|
+
linewidth=3,
|
|
194
|
+
color=paper_colors[color_forecast],
|
|
195
|
+
label="Forecast",
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
ax.fill_between(
|
|
199
|
+
df_ts.index,
|
|
200
|
+
df_ts[variable + "_lower"],
|
|
201
|
+
df_ts[variable + "_upper"],
|
|
202
|
+
color=paper_colors["GRAY_BARS"],
|
|
203
|
+
alpha=0.3,
|
|
204
|
+
edgecolor="none",
|
|
205
|
+
label="Confidence Interval",
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
temp_variable = variable
|
|
209
|
+
if auto_format_label:
|
|
210
|
+
if "-" in temp_variable:
|
|
211
|
+
temp_variable = "-".join(
|
|
212
|
+
[
|
|
213
|
+
j.title() if i == 0 else j.lower()
|
|
214
|
+
for i, j in enumerate(temp_variable.split("-"))
|
|
215
|
+
]
|
|
216
|
+
)
|
|
217
|
+
elif "_" in temp_variable:
|
|
218
|
+
temp_variable = " ".join(
|
|
219
|
+
[
|
|
220
|
+
j.title() if i == 0 else j.lower()
|
|
221
|
+
for i, j in enumerate(temp_variable.split("_"))
|
|
222
|
+
]
|
|
223
|
+
)
|
|
224
|
+
else:
|
|
225
|
+
temp_variable = " ".join(
|
|
226
|
+
[
|
|
227
|
+
j.title() if i == 0 else j.lower()
|
|
228
|
+
for i, j in enumerate(temp_variable.split())
|
|
229
|
+
]
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
ax.set(xlabel=f"{time_unit}", ylabel=f"{temp_variable} {units}")
|
|
233
|
+
ax.ticklabel_format(style="sci", axis="y", scilimits=(0, 0))
|
|
234
|
+
|
|
235
|
+
locators = {
|
|
236
|
+
"Year": (mdates.YearLocator(), mdates.MonthLocator()),
|
|
237
|
+
"Month": (mdates.MonthLocator(), mdates.WeekdayLocator()),
|
|
238
|
+
"Weekday": (mdates.WeekdayLocator(), mdates.DayLocator()),
|
|
239
|
+
"Day": (mdates.DayLocator(), mdates.HourLocator()),
|
|
240
|
+
"Hour": (mdates.HourLocator(), mdates.MinuteLocator()),
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if time_unit in locators:
|
|
244
|
+
major, minor = locators[time_unit]
|
|
245
|
+
ax.xaxis.set_major_locator(major)
|
|
246
|
+
ax.xaxis.set_minor_locator(minor)
|
|
247
|
+
|
|
248
|
+
ax.tick_params(axis="x", rotation=rot)
|
|
249
|
+
ax.grid(which="both")
|
|
250
|
+
ax.grid(which="minor", alpha=0.6, linestyle=":")
|
|
251
|
+
ax.grid(which="major", alpha=0.8, linestyle="--")
|
|
252
|
+
ax.legend(loc="center left", bbox_to_anchor=(1, 0.5))
|
|
253
|
+
|
|
254
|
+
return fig
|
|
255
|
+
|
|
256
|
+
|
|
126
257
|
def plot_interpolation_analysis(
|
|
127
258
|
df_original,
|
|
128
259
|
variable,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
direl_ts_tool_kit/__init__.py,sha256=W99Wd3BeEFKOxT51TApURElbDJvqIjD8u_-qDoCYSJ0,94
|
|
2
|
+
direl_ts_tool_kit/plot/__init__.py,sha256=CMwyv-kiE74nwr3MJPL7gWIJmcfZ8UQCRu7mBGGQ4rI,49
|
|
3
|
+
direl_ts_tool_kit/plot/plot_style.py,sha256=5YxoLXlYvzleTnBEGPwCmHQIJ0S96KPJspq_n-qMvpw,1069
|
|
4
|
+
direl_ts_tool_kit/plot/plot_ts.py,sha256=OuHgFlNyjW6BEleIKbv2LIt5MDlzfu5kM8gee4z_24U,23571
|
|
5
|
+
direl_ts_tool_kit/utilities/__init__.py,sha256=jMtxYZUtwlhgI99sxe_8MMzsDnxtbTP7Ivh9tUOeIwQ,25
|
|
6
|
+
direl_ts_tool_kit/utilities/data_prep.py,sha256=k3eOwQEEd5mxy2DtT_Gdo7BhkzEmSQqvMJ89y8mH5CQ,6024
|
|
7
|
+
direl_ts_tool_kit-0.10.0.dist-info/licenses/LICENCE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
direl_ts_tool_kit-0.10.0.dist-info/METADATA,sha256=dpNkbfrs3SKr-GKnR7Tur0Rk0cZqvCOKESQdQDoJpn8,5774
|
|
9
|
+
direl_ts_tool_kit-0.10.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
10
|
+
direl_ts_tool_kit-0.10.0.dist-info/top_level.txt,sha256=vMCRudnGnsdRg_6fUftnG8PF2Y1m0bjBDMf3pCAp6bc,18
|
|
11
|
+
direl_ts_tool_kit-0.10.0.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
direl_ts_tool_kit/__init__.py,sha256=W99Wd3BeEFKOxT51TApURElbDJvqIjD8u_-qDoCYSJ0,94
|
|
2
|
-
direl_ts_tool_kit/plot/__init__.py,sha256=CMwyv-kiE74nwr3MJPL7gWIJmcfZ8UQCRu7mBGGQ4rI,49
|
|
3
|
-
direl_ts_tool_kit/plot/plot_style.py,sha256=5YxoLXlYvzleTnBEGPwCmHQIJ0S96KPJspq_n-qMvpw,1069
|
|
4
|
-
direl_ts_tool_kit/plot/plot_ts.py,sha256=jAb_EruXvj0FIhvdm4BSqnGXY8dBAoPPusLE15owrwQ,19443
|
|
5
|
-
direl_ts_tool_kit/utilities/__init__.py,sha256=jMtxYZUtwlhgI99sxe_8MMzsDnxtbTP7Ivh9tUOeIwQ,25
|
|
6
|
-
direl_ts_tool_kit/utilities/data_prep.py,sha256=k3eOwQEEd5mxy2DtT_Gdo7BhkzEmSQqvMJ89y8mH5CQ,6024
|
|
7
|
-
direl_ts_tool_kit-0.9.0.dist-info/licenses/LICENCE,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
-
direl_ts_tool_kit-0.9.0.dist-info/METADATA,sha256=yGjaOHA9e78QX2x1YbEnDWeqMl-Cf2_Z9z7czZaLt20,5773
|
|
9
|
-
direl_ts_tool_kit-0.9.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
10
|
-
direl_ts_tool_kit-0.9.0.dist-info/top_level.txt,sha256=vMCRudnGnsdRg_6fUftnG8PF2Y1m0bjBDMf3pCAp6bc,18
|
|
11
|
-
direl_ts_tool_kit-0.9.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|