forecaster.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:prophet 作者: facebook 项目源码 文件源码
def plot_seasonality(self, name, ax=None, uncertainty=True):
        """Plot a custom seasonal component.

        Parameters
        ----------
        ax: Optional matplotlib Axes to plot on. One will be created if
            this is not provided.
        uncertainty: Optional boolean to plot uncertainty intervals.

        Returns
        -------
        a list of matplotlib artists
        """
        artists = []
        if not ax:
            fig = plt.figure(facecolor='w', figsize=(10, 6))
            ax = fig.add_subplot(111)
        # Compute seasonality from Jan 1 through a single period.
        start = pd.to_datetime('2017-01-01 0000')
        period = self.seasonalities[name]['period']
        end = start + pd.Timedelta(days=period)
        plot_points = 200
        days = pd.to_datetime(np.linspace(start.value, end.value, plot_points))
        df_y = self.seasonality_plot_df(days)
        seas = self.predict_seasonal_components(df_y)
        artists += ax.plot(df_y['ds'].dt.to_pydatetime(), seas[name], ls='-',
                            c='#0072B2')
        if uncertainty:
            artists += [ax.fill_between(
                df_y['ds'].dt.to_pydatetime(), seas[name + '_lower'],
                seas[name + '_upper'], color='#0072B2', alpha=0.2)]
        ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2)
        xticks = pd.to_datetime(np.linspace(start.value, end.value, 7)
            ).to_pydatetime()
        ax.set_xticks(xticks)
        if period <= 2:
            fmt_str = '{dt:%T}'
        elif period < 14:
            fmt_str = '{dt:%m}/{dt:%d} {dt:%R}'
        else:
            fmt_str = '{dt:%m}/{dt:%d}'
        ax.xaxis.set_major_formatter(FuncFormatter(
            lambda x, pos=None: fmt_str.format(dt=num2date(x))))
        ax.set_xlabel('ds')
        ax.set_ylabel(name)
        return artists
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号