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

Function plot_seasonality

python/prophet/plot.py:369–433  ·  view source on GitHub ↗

Plot a custom seasonal component. Parameters ---------- m: Prophet model. name: Seasonality name, like 'daily', 'weekly'. ax: Optional matplotlib Axes to plot on. One will be created if this is not provided. uncertainty: Optional boolean to plot uncertainty intervals

(m, name, ax=None, uncertainty=True, figsize=(10, 6))

Source from the content-addressed store, hash-verified

367
368
369def plot_seasonality(m, name, ax=None, uncertainty=True, figsize=(10, 6)):
370 """Plot a custom seasonal component.
371
372 Parameters
373 ----------
374 m: Prophet model.
375 name: Seasonality name, like 'daily', 'weekly'.
376 ax: Optional matplotlib Axes to plot on. One will be created if
377 this is not provided.
378 uncertainty: Optional boolean to plot uncertainty intervals, which will
379 only be done if m.uncertainty_samples > 0.
380 figsize: Optional tuple width, height in inches.
381
382 Returns
383 -------
384 a list of matplotlib artists
385 """
386 artists = []
387 if not ax:
388 fig = plt.figure(facecolor='w', figsize=figsize)
389 ax = fig.add_subplot(111)
390 # Compute seasonality from Jan 1 through a single period.
391 start = pd.to_datetime('2017-01-01 0000')
392 period = m.seasonalities[name]['period']
393 end = start + pd.Timedelta(days=period)
394 plot_points = 200
395 days = pd.to_datetime(np.linspace(start.value, end.value, plot_points))
396 df_y = seasonality_plot_df(m, days)
397 seas = m.predict_seasonal_components(df_y)
398 artists += ax.plot(df_y['ds'], seas[name], ls='-',
399 c='#0072B2')
400 if uncertainty and m.uncertainty_samples:
401 artists += [ax.fill_between(
402 df_y['ds'], seas[name + '_lower'],
403 seas[name + '_upper'], color='#0072B2', alpha=0.2)]
404 ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2)
405 n_ticks = 8
406 xticks = pd.to_datetime(np.linspace(start.value, end.value, n_ticks)
407 ).to_pydatetime()
408 ax.set_xticks(xticks)
409 if name == 'yearly':
410 fmt = FuncFormatter(
411 lambda x, pos=None: '{dt:%B} {dt.day}'.format(dt=num2date(x)))
412 ax.set_xlabel('Day of year')
413 elif name == 'weekly':
414 fmt = FuncFormatter(
415 lambda x, pos=None: '{dt:%A}'.format(dt=num2date(x)))
416 ax.set_xlabel('Day of Week')
417 elif name == 'daily':
418 fmt = FuncFormatter(
419 lambda x, pos=None: '{dt:%T}'.format(dt=num2date(x)))
420 ax.set_xlabel('Hour of day')
421 elif period <= 2:
422 fmt = FuncFormatter(
423 lambda x, pos=None: '{dt:%T}'.format(dt=num2date(x)))
424 ax.set_xlabel('Hours')
425 else:
426 fmt = FuncFormatter(

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…