I am generating some subplots based on a groupby with pandas. It seems that there are some errors in my code, but I am unsure where the error exists.
My custom data shows actual values (12.7, 43.9, etc.) for some data points and the text string customdata[1] for others.
My colorscale also has some points that show up as black, rather than a value in the colorscale.
Any wisdom on what I should do differently?
gb_subplots = res2.groupby([“restaurant_name”, “cuisine_type”]).agg({“tot_cust_at_rest”: “mean”, “FH_rev”: “sum”, “cost_of_the_order”: “mean”}).reset_index().dropna()
cuis = [“American”, “Vietnamese”, “Spanish”, “French”, “Southern”, “Chinese”]fig = make_subplots(3, 2, shared_xaxes=True, shared_yaxes=True, subplot_titles=cuis)
loc = [[1, 1], [1, 2],
[2, 1], [2, 2],
[3, 1], [3, 2]]for subplot in range(0, 6):
cd=pd.concat([gb_subplots[gb_subplots.cuisine_type==cuis[subplot]].restaurant_name,
pd.Series([round(k, 2) for k in gb_subplots[gb_subplots.cuisine_type==cuis[subplot]].cost_of_the_order])], axis=1,)
fig.add_trace(go.Scatter(
x=gb_subplots[gb_subplots.cuisine_type==cuis[subplot]].tot_cust_at_rest,
y=gb_subplots[gb_subplots.cuisine_type==cuis[subplot]].FH_rev,
mode=“markers”, showlegend=False,
customdata=cd,
hovertemplate=
“%{customdata[0]}
” +
“Number of Customers: %{x}
” +
“Revenue: %{y}
” +
“Cost of Order: %{customdata[1]}
” +
“”,
marker={“color”:colorscale}),
row=loc[subplot][0], col=loc[subplot][1])fig.for_each_xaxis(lambda x: x.update(showgrid=False, zeroline=False, range=[-20, 250]))
fig.for_each_yaxis(lambda x: x.update(showgrid=False, zeroline=False, range=[-50, 800]))
fig.update_traces(marker={“color”: gb_subplots[gb_subplots.cuisine_type==cuis[subplot]].cost_of_the_order,
“colorscale”:colorscale[3:], “colorbar”:{“title”:“Average Cost”, “thickness”: 30, “outlinecolor”: “white”}})
fig3 = layout_func(fig)
The data on color (cost, listed below) shows a full list of 41 values with zero nans.
print(gb_subplots[gb_subplots.cuisine_type==“American”].restaurant_name)
Why are there discrepancies in how plotly is visualizing the data?