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

Function plot_components_plotly

python/prophet/plot.py:716–776  ·  view source on GitHub ↗

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: P

(
        m, fcst, uncertainty=True, plot_cap=True, figsize=(900, 200))

Source from the content-addressed store, hash-verified

714
715
716def plot_components_plotly(
717 m, fcst, uncertainty=True, plot_cap=True, figsize=(900, 200)):
718 """Plot the Prophet forecast components using Plotly.
719 See plot_plotly() for Plotly setup instructions
720
721 Will plot whichever are available of: trend, holidays, weekly
722 seasonality, yearly seasonality, and additive and multiplicative extra
723 regressors.
724
725 Parameters
726 ----------
727 m: Prophet model.
728 fcst: pd.DataFrame output of m.predict.
729 uncertainty: Optional boolean to plot uncertainty intervals, which will
730 only be done if m.uncertainty_samples > 0.
731 plot_cap: Optional boolean indicating if the capacity should be shown
732 in the figure, if available.
733 figsize: Set the size for the subplots (in px).
734
735 Returns
736 -------
737 A Plotly Figure.
738 """
739
740 # Identify components to plot and get their Plotly props
741 components = {}
742 components['trend'] = get_forecast_component_plotly_props(
743 m, fcst, 'trend', uncertainty, plot_cap)
744 if m.train_holiday_names is not None and 'holidays' in fcst:
745 components['holidays'] = get_forecast_component_plotly_props(
746 m, fcst, 'holidays', uncertainty)
747
748 regressors = {'additive': False, 'multiplicative': False}
749 for name, props in m.extra_regressors.items():
750 regressors[props['mode']] = True
751 for mode in ['additive', 'multiplicative']:
752 if regressors[mode] and 'extra_regressors_{}'.format(mode) in fcst:
753 components['extra_regressors_{}'.format(mode)] = get_forecast_component_plotly_props(
754 m, fcst, 'extra_regressors_{}'.format(mode))
755 for seasonality in m.seasonalities:
756 components[seasonality] = get_seasonality_plotly_props(m, seasonality)
757
758 # Create Plotly subplot figure and add the components to it
759 fig = make_subplots(rows=len(components), cols=1, print_grid=False)
760 fig['layout'].update(go.Layout(
761 showlegend=False,
762 width=figsize[0],
763 height=figsize[1] * len(components)
764 ))
765 for i, name in enumerate(components):
766 if i == 0:
767 xaxis = fig['layout']['xaxis']
768 yaxis = fig['layout']['yaxis']
769 else:
770 xaxis = fig['layout']['xaxis{}'.format(i + 1)]
771 yaxis = fig['layout']['yaxis{}'.format(i + 1)]
772 xaxis.update(components[name]['xaxis'])
773 yaxis.update(components[name]['yaxis'])

Callers

nothing calls this directly

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…