in python/prophet/plot.py [0:0]
def plot_seasonality(m, name, ax=None, uncertainty=True, figsize=(10, 6)):
"""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, which will
only be done if m.uncertainty_samples > 0.
figsize: Optional tuple width, height in inches.
Returns
-------
a list of matplotlib artists
"""
artists = []
if not ax:
fig = plt.figure(facecolor='w', figsize=figsize)
ax = fig.add_subplot(111)
# Compute seasonality from Jan 1 through a single period.
start = pd.to_datetime('2017-01-01 0000')
period = m.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 = seasonality_plot_df(m, days)
seas = m.predict_seasonal_components(df_y)
artists += ax.plot(df_y['ds'].dt.to_pydatetime(), seas[name], ls='-',
c='#0072B2')
if uncertainty and m.uncertainty_samples:
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)
n_ticks = 8
xticks = pd.to_datetime(np.linspace(start.value, end.value, n_ticks)
).to_pydatetime()
ax.set_xticks(xticks)
if name == 'yearly':
fmt = FuncFormatter(
lambda x, pos=None: '{dt:%B} {dt.day}'.format(dt=num2date(x)))
ax.set_xlabel('Day of year')
elif name == 'weekly':
fmt = FuncFormatter(
lambda x, pos=None: '{dt:%A}'.format(dt=num2date(x)))
ax.set_xlabel('Day of Week')
elif name == 'daily':
fmt = FuncFormatter(
lambda x, pos=None: '{dt:%T}'.format(dt=num2date(x)))
ax.set_xlabel('Hour of day')
elif period <= 2:
fmt = FuncFormatter(
lambda x, pos=None: '{dt:%T}'.format(dt=num2date(x)))
ax.set_xlabel('Hours')
else:
fmt = FuncFormatter(
lambda x, pos=None: '{:.0f}'.format(pos * period / (n_ticks - 1)))
ax.set_xlabel('Days')
ax.xaxis.set_major_formatter(fmt)
ax.set_ylabel(name)
if m.seasonalities[name]['mode'] == 'multiplicative':
ax = set_y_as_percent(ax)
return artists