MCPcopy Index your code
hub / github.com/facebook/prophet / get_seasonality_plotly_props

Function get_seasonality_plotly_props

python/prophet/plot.py:944–1025  ·  view source on GitHub ↗

Prepares a dictionary for plotting the selected seasonality with Plotly Parameters ---------- m: Prophet model. name: Name of the component to plot. uncertainty: Optional boolean to plot uncertainty intervals, which will only be done if m.uncertainty_samples > 0. Re

(m, name, uncertainty=True)

Source from the content-addressed store, hash-verified

942
943
944def get_seasonality_plotly_props(m, name, uncertainty=True):
945 """Prepares a dictionary for plotting the selected seasonality with Plotly
946
947 Parameters
948 ----------
949 m: Prophet model.
950 name: Name of the component to plot.
951 uncertainty: Optional boolean to plot uncertainty intervals, which will
952 only be done if m.uncertainty_samples > 0.
953
954 Returns
955 -------
956 A dictionary with Plotly traces, xaxis and yaxis
957 """
958 prediction_color = '#0072B2'
959 error_color = 'rgba(0, 114, 178, 0.2)' # '#0072B2' with 0.2 opacity
960 line_width = 2
961 zeroline_color = '#AAA'
962
963 # Compute seasonality from Jan 1 through a single period.
964 start = pd.to_datetime('2017-01-01 0000')
965 period = m.seasonalities[name]['period']
966 end = start + pd.Timedelta(days=period)
967 if (m.history['ds'].dt.hour == 0).all(): # Day Precision
968 plot_points = np.floor(period).astype(int)
969 elif (m.history['ds'].dt.minute == 0).all(): # Hour Precision
970 plot_points = np.floor(period * 24).astype(int)
971 else: # Minute Precision
972 plot_points = np.floor(period * 24 * 60).astype(int)
973 days = pd.to_datetime(np.linspace(start.value, end.value, plot_points, endpoint=False))
974 df_y = seasonality_plot_df(m, days)
975 seas = m.predict_seasonal_components(df_y)
976
977 traces = []
978 traces.append(go.Scatter(
979 name=name,
980 x=df_y['ds'],
981 y=seas[name],
982 mode='lines',
983 line=go.scatter.Line(color=prediction_color, width=line_width)
984 ))
985 if uncertainty and m.uncertainty_samples and (seas[name + '_upper'] != seas[name + '_lower']).any():
986 traces.append(go.Scatter(
987 name=name + '_upper',
988 x=df_y['ds'],
989 y=seas[name + '_upper'],
990 mode='lines',
991 line=go.scatter.Line(width=0, color=error_color)
992 ))
993 traces.append(go.Scatter(
994 name=name + '_lower',
995 x=df_y['ds'],
996 y=seas[name + '_lower'],
997 mode='lines',
998 line=go.scatter.Line(width=0, color=error_color),
999 fillcolor=error_color,
1000 fill='tonexty'
1001 ))

Callers 2

plot_components_plotlyFunction · 0.85
plot_seasonality_plotlyFunction · 0.85

Calls 2

seasonality_plot_dfFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…