Hello,
I’m trying to combine two bar graphs into one in order to share a legend and it’s legend functionality. However, when running the code, I’m getting an error.
Error is as follows:
Traceback (most recent call last):
File "/root/workspace/pages/ind_item.py", line 302, in time_series_show_snapshot
row=1, col=1))
TypeError: 'module' object is not callable
The code runs as follows:
@callback(
dash.dependencies.Output('snapshot_timeseries', 'figure'),
dash.dependencies.Input('item_dropdown', 'value'),
)
def time_series_show_snapshot(item):
df_table = df_final[df_final['ord_base7']==item].groupby(['ord_base7', 'item_desc','model', 'snapshot']).agg({'diff':'sum',
'predicted_sales':'sum', 'sales_dollars':'sum'}).reset_index()
df_table.loc[:, 'MAPE'] = np.round(df_table.loc[:, 'diff']/ df_table.loc[:, 'sales_dollars'], 4)
df_table.loc[:, 'ACCURACY'] = 1 - df_table.loc[:,'MAPE']
df_table.loc[:, 'BIAS'] = np.round((df_table.loc[:,'predicted_sales']- df_table.loc[:, 'sales_dollars'])/ df_table.loc[:, 'sales_dollars'], 4)
# print("Data for time series", df_[['dmand_yr_mo', 'ord_base7', 'snapshot', 'model', 'location_type', 'sales_dollars']].sort_values('dmand_yr_mo'))
fig = go.Figure()
fig = make_subplots(rows=2, cols=1)
fig.add_trace(go.bar(
x= df_table["snapshot"],
y=df_table["MAPE"],
row=1, col=1))
# color="model", barmode="group", title = "MAPE by Snapshot")
fig.add_trace(go.bar(
x= df_table["snapshot"],
y=df_table["BIAS"],
row=2, col=1))
return fig
I initially based my code off the following post: [initial post](python 3.x - Sharing same legends for subplots in plotly - Stack Overflow)