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

Function get_forecast_component_plotly_props

python/prophet/plot.py:838–941  ·  view source on GitHub ↗

Prepares a dictionary for plotting the selected forecast component with Plotly Parameters ---------- m: Prophet model. fcst: pd.DataFrame output of m.predict. name: Name of the component to plot. uncertainty: Optional boolean to plot uncertainty intervals, which will

(m, fcst, name, uncertainty=True, plot_cap=False)

Source from the content-addressed store, hash-verified

836
837
838def get_forecast_component_plotly_props(m, fcst, name, uncertainty=True, plot_cap=False):
839 """Prepares a dictionary for plotting the selected forecast component with Plotly
840
841 Parameters
842 ----------
843 m: Prophet model.
844 fcst: pd.DataFrame output of m.predict.
845 name: Name of the component to plot.
846 uncertainty: Optional boolean to plot uncertainty intervals, which will
847 only be done if m.uncertainty_samples > 0.
848 plot_cap: Optional boolean indicating if the capacity should be shown
849 in the figure, if available.
850
851 Returns
852 -------
853 A dictionary with Plotly traces, xaxis and yaxis
854 """
855 prediction_color = '#0072B2'
856 error_color = 'rgba(0, 114, 178, 0.2)' # '#0072B2' with 0.2 opacity
857 cap_color = 'black'
858 zeroline_color = '#AAA'
859 line_width = 2
860
861 range_margin = (fcst['ds'].max() - fcst['ds'].min()) * 0.05
862 range_x = [fcst['ds'].min() - range_margin, fcst['ds'].max() + range_margin]
863
864 text = None
865 mode = 'lines'
866 if name == 'holidays':
867
868 # Combine holidays into one hover text
869 holidays = m.construct_holiday_dataframe(fcst['ds'])
870 holiday_features, _, _ = m.make_holiday_features(fcst['ds'], holidays)
871 holiday_features.columns = holiday_features.columns.str.replace('_delim_', '', regex=False)
872 holiday_features.columns = holiday_features.columns.str.replace('+0', '', regex=False)
873 text = pd.Series(data='', index=holiday_features.index)
874 for holiday_feature, idxs in holiday_features.items():
875 text[idxs.astype(bool) & (text != '')] += '<br>' # Add newline if additional holiday
876 text[idxs.astype(bool)] += holiday_feature
877
878 traces = []
879 traces.append(go.Scatter(
880 name=name,
881 x=fcst['ds'],
882 y=fcst[name],
883 mode=mode,
884 line=go.scatter.Line(color=prediction_color, width=line_width),
885 text=text,
886 ))
887 if uncertainty and m.uncertainty_samples and (fcst[name + '_upper'] != fcst[name + '_lower']).any():
888 if mode == 'markers':
889 traces[0].update(
890 error_y=dict(
891 type='data',
892 symmetric=False,
893 array=fcst[name + '_upper'],
894 arrayminus=fcst[name + '_lower'],
895 width=0,

Callers 2

plot_components_plotlyFunction · 0.85

Calls 2

make_holiday_featuresMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…