Plot the yearly component of the forecast. Parameters ---------- m: Prophet model. ax: Optional matplotlib Axes to plot on. One will be created if this is not provided. uncertainty: Optional boolean to plot uncertainty intervals, which will only be done if m.unce
(m, ax=None, uncertainty=True, yearly_start=0, figsize=(10, 6), name='yearly')
| 320 | |
| 321 | |
| 322 | def plot_yearly(m, ax=None, uncertainty=True, yearly_start=0, figsize=(10, 6), name='yearly'): |
| 323 | """Plot the yearly component of the forecast. |
| 324 | |
| 325 | Parameters |
| 326 | ---------- |
| 327 | m: Prophet model. |
| 328 | ax: Optional matplotlib Axes to plot on. One will be created if |
| 329 | this is not provided. |
| 330 | uncertainty: Optional boolean to plot uncertainty intervals, which will |
| 331 | only be done if m.uncertainty_samples > 0. |
| 332 | yearly_start: Optional int specifying the start day of the yearly |
| 333 | seasonality plot. 0 (default) starts the year on Jan 1. 1 shifts |
| 334 | by 1 day to Jan 2, and so on. |
| 335 | figsize: Optional tuple width, height in inches. |
| 336 | name: Name of seasonality component if previously changed from default 'yearly'. |
| 337 | |
| 338 | Returns |
| 339 | ------- |
| 340 | a list of matplotlib artists |
| 341 | """ |
| 342 | artists = [] |
| 343 | if not ax: |
| 344 | fig = plt.figure(facecolor='w', figsize=figsize) |
| 345 | ax = fig.add_subplot(111) |
| 346 | # Compute yearly seasonality for a Jan 1 - Dec 31 sequence of dates. |
| 347 | days = (pd.date_range(start='2017-01-01', periods=365) + |
| 348 | pd.Timedelta(days=yearly_start)) |
| 349 | df_y = seasonality_plot_df(m, days) |
| 350 | seas = m.predict_seasonal_components(df_y) |
| 351 | artists += ax.plot( |
| 352 | df_y['ds'], seas[name], ls='-', c='#0072B2') |
| 353 | if uncertainty and m.uncertainty_samples: |
| 354 | artists += [ax.fill_between( |
| 355 | df_y['ds'], seas[name + '_lower'], |
| 356 | seas[name + '_upper'], color='#0072B2', alpha=0.2)] |
| 357 | ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2) |
| 358 | months = MonthLocator(range(1, 13), bymonthday=1, interval=2) |
| 359 | ax.xaxis.set_major_formatter(FuncFormatter( |
| 360 | lambda x, pos=None: '{dt:%B} {dt.day}'.format(dt=num2date(x)))) |
| 361 | ax.xaxis.set_major_locator(months) |
| 362 | ax.set_xlabel('Day of year') |
| 363 | ax.set_ylabel(name) |
| 364 | if m.seasonalities[name]['mode'] == 'multiplicative': |
| 365 | ax = set_y_as_percent(ax) |
| 366 | return artists |
| 367 | |
| 368 | |
| 369 | def plot_seasonality(m, name, ax=None, uncertainty=True, figsize=(10, 6)): |
no test coverage detected
searching dependent graphs…