MCPcopy
hub / github.com/facebook/prophet / plot_yearly

Function plot_yearly

python/prophet/plot.py:322–366  ·  view source on GitHub ↗

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')

Source from the content-addressed store, hash-verified

320
321
322def 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
369def plot_seasonality(m, name, ax=None, uncertainty=True, figsize=(10, 6)):

Callers 1

plot_componentsFunction · 0.85

Calls 4

seasonality_plot_dfFunction · 0.85
set_y_as_percentFunction · 0.85
plotMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…