from matplotlib import pyplot as plt
def my_plot(title,
m, fcst, ax=None, uncertainty=True, plot_cap=True, xlabel='ds', ylabel='y', abnormal_points=None
):
"""Plot the Prophet forecast.
Parameters
----------
m: Prophet model.
fcst: pd.DataFrame output of m.predict.
ax: Optional matplotlib axes on which to plot.
uncertainty: Optional boolean to plot uncertainty intervals.
plot_cap: Optional boolean indicating if the capacity should be shown
in the figure, if available.
xlabel: Optional label name on X-axis
ylabel: Optional label name on Y-axis
Returns
-------
A matplotlib figure.
"""
if ax is None:
fig = plt.figure(facecolor='w', figsize=(10, 6))
ax = fig.add_subplot(111)
else:
fig = ax.get_figure()
fcst_t = fcst['ds'].dt.to_pydatetime()
ax.plot(m.history['ds'].dt.to_pydatetime(), m.history['y'], 'k.', label='y')
ax.legend()
ax.plot(fcst_t, fcst['yhat'], ls='-', c='#0072B2', label='predicted y')
ax.legend()
ax.fill_between(fcst_t, 0, fcst['yhat_upper'],
color='#0072B2', alpha=0.2, label='predicted upper y')
# ax.plot(fcst_t, fcst['yhat_upper'], ls='--', color='#0072B2', alpha=0.2, label='predicted upper y')
ax.legend()
if abnormal_points is not None:
ax.plot(abnormal_points['ds'], abnormal_points['y'], "rX", label='abnormal points')
ax.legend()
ax.set_title(title)
ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2)
ax.set_xlabel(xlabel)
ax.set_ylabel(ylabel)
fig.tight_layout()
plt.savefig("png/{}.png".format(title))
return fig