def update_forecast(json_data): """ update forecast figure""" df_fcst = pd.read_json(json_data, orient='split') trace_f = [] selected_stocks = df_fcst.columns.tolist() selected_stocks = [ stock for stock in selected_stocks if stock != 'type_obs' ] type_obs = df_fcst['type_obs'].unique().tolist() for stock in selected_stocks: # loop over types to differentiate forecast vs observed for observed_type in type_obs: x = df_fcst[df_fcst['type_obs'] == observed_type][stock].index y = df_fcst[df_fcst['type_obs'] == observed_type][stock] tmp_name = observed_type + ' ' + stock # append Plotly object trace_f.append(dashf.go_scatter(x=x, y=y, name=tmp_name)) figure = dashf.scatter_figure(trace=trace_f, min_range=df_fcst.index.min(), max_range=df_fcst.index.max(), text_title='Stock Prices Forecast') return figure
def update_trend(json_data): """ update trned component figure""" df_season = pd.read_json(json_data, orient='split') trace1 = [] # append plotly object trace1.append(dashf.go_scatter(x=df_season.index, y=df_season['trend'], name='trend')) # update figure figure = dashf.scatter_figure(trace1, min_range=df_season.index.min(), max_range=df_season.index.max(), text_title='Trend Component') return figure
def update_residual(json_data): """ update residual figure""" df_season = pd.read_json(json_data, orient='split') trace1 = [] # append plotly object trace1.append(dashf.go_scatter(x=df_season.index, y=df_season['resid'], name='residuals')) # update figure figure = dashf.scatter_figure(trace1, min_range=df_season.index.min(), max_range=df_season.index.max(), text_title='Residuals') return figure
def update_graph(selected_dropdown_value): """update stock price figure """ trace1 = [] df_sub = df for stock in selected_dropdown_value: # append Plotly Scatter object trace1.append( dashf.go_scatter(x=df_sub.index, y=df_sub[stock], name=stock)) # Update figure figure = dashf.scatter_figure(trace1, min_range=df_sub.index.min(), max_range=df_sub.index.max(), text_title='Stock Prices') return figure