in python/prophet/plot.py [0:0]
def plot_components_plotly(
m, fcst, uncertainty=True, plot_cap=True, figsize=(900, 200)):
"""Plot the Prophet forecast components using Plotly.
See plot_plotly() for Plotly setup instructions
Will plot whichever are available of: trend, holidays, weekly
seasonality, yearly seasonality, and additive and multiplicative extra
regressors.
Parameters
----------
m: Prophet model.
fcst: pd.DataFrame output of m.predict.
uncertainty: Optional boolean to plot uncertainty intervals, which will
only be done if m.uncertainty_samples > 0.
plot_cap: Optional boolean indicating if the capacity should be shown
in the figure, if available.
figsize: Set the size for the subplots (in px).
Returns
-------
A Plotly Figure.
"""
# Identify components to plot and get their Plotly props
components = {}
components['trend'] = get_forecast_component_plotly_props(
m, fcst, 'trend', uncertainty, plot_cap)
if m.train_holiday_names is not None and 'holidays' in fcst:
components['holidays'] = get_forecast_component_plotly_props(
m, fcst, 'holidays', uncertainty)
regressors = {'additive': False, 'multiplicative': False}
for name, props in m.extra_regressors.items():
regressors[props['mode']] = True
for mode in ['additive', 'multiplicative']:
if regressors[mode] and 'extra_regressors_{}'.format(mode) in fcst:
components['extra_regressors_{}'.format(mode)] = get_forecast_component_plotly_props(
m, fcst, 'extra_regressors_{}'.format(mode))
for seasonality in m.seasonalities:
components[seasonality] = get_seasonality_plotly_props(m, seasonality)
# Create Plotly subplot figure and add the components to it
fig = make_subplots(rows=len(components), cols=1, print_grid=False)
fig['layout'].update(go.Layout(
showlegend=False,
width=figsize[0],
height=figsize[1] * len(components)
))
for i, name in enumerate(components):
if i == 0:
xaxis = fig['layout']['xaxis']
yaxis = fig['layout']['yaxis']
else:
xaxis = fig['layout']['xaxis{}'.format(i + 1)]
yaxis = fig['layout']['yaxis{}'.format(i + 1)]
xaxis.update(components[name]['xaxis'])
yaxis.update(components[name]['yaxis'])
for trace in components[name]['traces']:
fig.append_trace(trace, i + 1, 1)
return fig