zoukankan      html  css  js  c++  java
  • python 绘图 异常点绘制使用 ax.plot(abnormal_points['ds'], abnormal_points['y'], "rX", label='abnormal points')

    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
    
  • 相关阅读:
    Android学习笔记——Menu(三)
    Android学习笔记——Menu(二)
    Android学习笔记——Menu(一)
    Python学习笔记(三)——迭代
    Python学习笔记(二)——高级特性
    Python学习笔记(一)——基本知识点
    Java中遍历Map的常用方法
    比较Java中几个常用集合添加元素的效率
    Java计算两个程序运行时间
    Java中的并发编程集合使用
  • 原文地址:https://www.cnblogs.com/bonelee/p/9705030.html
Copyright © 2011-2022 走看看