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
python 绘图 异常点绘制使用 ax.plot(abnormal_points['ds'], abnormal_points['y'], "rX", label='abnormal points')
免责声明:文章转载自《python 绘图 异常点绘制使用 ax.plot(abnormal_points['ds'], abnormal_points['y'], "rX", label='abnormal points')》仅用于学习参考。如对内容有疑问,请及时联系本站处理。
上篇清北学堂北京大学吴耀轩神仙讲课day5摘要安卓中多线程间通信方式下篇
宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=