Hi all - my goal is to generate multiple boxplots based on parameters a user selects using Dash and Plotly.
I have the initial part down of creating boxplots dynamically, and adding a new subplot based on the primary dimension, and within each subplot a new Box based on the secondary dimension. My final goal is to overlay a simple line over each box representing a reference point (which will also be configurable).
Currently, my approach is to generate alternate X-axis and use go.Scatter() to generate lines (i’m referencing both of these posts):
My goal is very similar - do the same thing but on a group of subplots. My solution is very close, but only works for the first Subplot, and doesn’t work for the remaining 2 subplots… it blocks out the Box and only displays the line! If I remove, the boxplots show just fine.
fig = make_subplots(rows=1, cols=len(p_data), subplot_titles=p_data)
for s in range(0,len(p_data)):
for w in range(0,len(s_data)):
y0 = df1[(df1[primary_config] == p_data[s]) & (df1[secondary_config] == s_data[w])]['Avg $/mt']
x0 = df_s[(df_s[primary_config] == p_data[s]) & (df_s[secondary_config] == s_data[w])]['Avg $/mt']
fig.add_trace(go.Box(xaxis='x1', y=y0, name=s_data[w],line=dict(color=colors[s]), fillcolor=colors[s]), row=1, col=s+1)
# fig.add_trace(go.Scatter(x=[s_data[w]]*len(x0), y=x0, name=s_data[w], mode='markers', marker=dict(symbol='diamond', color='black')), row=1, col=s+1)
fig.update_layout(showlegend=False)
fig.layout.xaxis4 = go.layout.XAxis(range=[0, 4], overlaying='x', showticklabels=False)
fig.add_trace(go.Scatter(x = [.25, .75], y = [800, 800], mode='lines', xaxis='x4', showlegend=False))
fig.layout.xaxis5 = go.layout.XAxis(range=[0, 4], overlaying='x2', showticklabels=False)
fig.add_trace(go.Scatter(x = [.25, .75], y = [700, 700], mode='lines', xaxis='x5', showlegend=False))
fig.layout.xaxis6 = go.layout.XAxis(range=[0, 4], overlaying='x3', showticklabels=False)
fig.add_trace(go.Scatter(x = [.25, .75], y = [700, 700], mode='lines', xaxis='x6', showlegend=False))