Plot a particular component of the forecast. Parameters ---------- m: Prophet model. fcst: pd.DataFrame output of m.predict. name: Name of the component to plot. ax: Optional matplotlib Axes to plot on. uncertainty: Optional boolean to plot uncertainty intervals, which w
(
m, fcst, name, ax=None, uncertainty=True, plot_cap=False, figsize=(10, 6)
)
| 202 | |
| 203 | |
| 204 | def plot_forecast_component( |
| 205 | m, fcst, name, ax=None, uncertainty=True, plot_cap=False, figsize=(10, 6) |
| 206 | ): |
| 207 | """Plot a particular component of the forecast. |
| 208 | |
| 209 | Parameters |
| 210 | ---------- |
| 211 | m: Prophet model. |
| 212 | fcst: pd.DataFrame output of m.predict. |
| 213 | name: Name of the component to plot. |
| 214 | ax: Optional matplotlib Axes to plot on. |
| 215 | uncertainty: Optional boolean to plot uncertainty intervals, which will |
| 216 | only be done if m.uncertainty_samples > 0. |
| 217 | plot_cap: Optional boolean indicating if the capacity should be shown |
| 218 | in the figure, if available. |
| 219 | figsize: Optional tuple width, height in inches. |
| 220 | |
| 221 | Returns |
| 222 | ------- |
| 223 | a list of matplotlib artists |
| 224 | """ |
| 225 | artists = [] |
| 226 | if not ax: |
| 227 | fig = plt.figure(facecolor='w', figsize=figsize) |
| 228 | ax = fig.add_subplot(111) |
| 229 | fcst_t = fcst['ds'] |
| 230 | artists += ax.plot(fcst_t, fcst[name], ls='-', c='#0072B2') |
| 231 | if 'cap' in fcst and plot_cap: |
| 232 | artists += ax.plot(fcst_t, fcst['cap'], ls='--', c='k') |
| 233 | if m.logistic_floor and 'floor' in fcst and plot_cap: |
| 234 | ax.plot(fcst_t, fcst['floor'], ls='--', c='k') |
| 235 | if uncertainty and m.uncertainty_samples: |
| 236 | artists += [ax.fill_between( |
| 237 | fcst_t, fcst[name + '_lower'], fcst[name + '_upper'], |
| 238 | color='#0072B2', alpha=0.2)] |
| 239 | # Specify formatting to workaround matplotlib issue #12925 |
| 240 | locator = AutoDateLocator(interval_multiples=False) |
| 241 | formatter = AutoDateFormatter(locator) |
| 242 | ax.xaxis.set_major_locator(locator) |
| 243 | ax.xaxis.set_major_formatter(formatter) |
| 244 | ax.grid(True, which='major', c='gray', ls='-', lw=1, alpha=0.2) |
| 245 | ax.set_xlabel('ds') |
| 246 | ax.set_ylabel(name) |
| 247 | if name in m.component_modes['multiplicative']: |
| 248 | ax = set_y_as_percent(ax) |
| 249 | return artists |
| 250 | |
| 251 | |
| 252 | def seasonality_plot_df(m, ds): |
no test coverage detected
searching dependent graphs…