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

Function plot_components

python/prophet/plot.py:99–201  ·  view source on GitHub ↗

Plot the Prophet forecast components. 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. unc

(
    m, fcst, uncertainty=True, plot_cap=True, weekly_start=0, yearly_start=0,
    figsize=None
)

Source from the content-addressed store, hash-verified

97
98
99def plot_components(
100 m, fcst, uncertainty=True, plot_cap=True, weekly_start=0, yearly_start=0,
101 figsize=None
102):
103 """Plot the Prophet forecast components.
104
105 Will plot whichever are available of: trend, holidays, weekly
106 seasonality, yearly seasonality, and additive and multiplicative extra
107 regressors.
108
109 Parameters
110 ----------
111 m: Prophet model.
112 fcst: pd.DataFrame output of m.predict.
113 uncertainty: Optional boolean to plot uncertainty intervals, which will
114 only be done if m.uncertainty_samples > 0.
115 plot_cap: Optional boolean indicating if the capacity should be shown
116 in the figure, if available.
117 weekly_start: Optional int specifying the start day of the weekly
118 seasonality plot. 0 (default) starts the week on Sunday. 1 shifts
119 by 1 day to Monday, and so on.
120 yearly_start: Optional int specifying the start day of the yearly
121 seasonality plot. 0 (default) starts the year on Jan 1. 1 shifts
122 by 1 day to Jan 2, and so on.
123 figsize: Optional tuple width, height in inches.
124
125 Returns
126 -------
127 A matplotlib figure.
128 """
129 # Identify components to be plotted
130 components = ['trend']
131 if m.train_holiday_names is not None and 'holidays' in fcst:
132 components.append('holidays')
133 # Plot weekly seasonality, if present
134 if 'weekly' in m.seasonalities and 'weekly' in fcst:
135 components.append('weekly')
136 # Yearly if present
137 if 'yearly' in m.seasonalities and 'yearly' in fcst:
138 components.append('yearly')
139 # Other seasonalities
140 components.extend([
141 name for name in sorted(m.seasonalities)
142 if name in fcst and name not in ['weekly', 'yearly']
143 ])
144 regressors = {'additive': False, 'multiplicative': False}
145 for name, props in m.extra_regressors.items():
146 regressors[props['mode']] = True
147 for mode in ['additive', 'multiplicative']:
148 if regressors[mode] and 'extra_regressors_{}'.format(mode) in fcst:
149 components.append('extra_regressors_{}'.format(mode))
150 npanel = len(components)
151
152 figsize = figsize if figsize else (9, 3 * npanel)
153 fig, axes = plt.subplots(npanel, 1, facecolor='w', figsize=figsize)
154
155 if npanel == 1:
156 axes = [axes]

Callers 1

plot_componentsMethod · 0.90

Calls 5

plot_forecast_componentFunction · 0.85
plot_weeklyFunction · 0.85
plot_yearlyFunction · 0.85
plot_seasonalityFunction · 0.85
set_y_as_percentFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…