How to overlay graph objects with go.add_trace rather than place them adjacently

Hello folks,

I have been attempting to create a px.strip graph with the group mean overlaid on top of it, similar to a typical GraphPad rendering.

I have been successful created a figure using px.scatter and appending a “boxplot” of the average for each group using add_trace and go.Box, however, this lacks the jitter of the points I’m looking for.

For whatever reason, when I use px.strip, my appended go.Box trace is grouped adjacently with the strip element but not overlaid.

Is there any way to achieve this (or, alternatively, add the jitter to px.scatter)?

I’ve written a simplified example for your reference:

import pandas as pd
import plotly.express as px
import plotly.graph_objects as go

data = {"Condition": ["Control", "Control", "Control", "Control", "Control", "Treatment", "Treatment", "Treatment", "Treatment", "Treatment"], "Read-out": [1.2, 1.5, 2.4, 2.8, 3, 5.2, 5.7, 8, 6.4, 7.2]}
df = pd.DataFrame(data)
df_ave = df.groupby(by = ["Condition"])["Read-out"].mean().reset_index()

fig = px.strip(df, x = "Condition", y = "Read-out")
fig.add_trace(go.Box(x = df_ave["Condition"], y = df_ave["Read-out"]))
fig.show()

fig = px.scatter(df, x = "Condition", y = "Read-out")
fig.add_trace(go.Box(x = df_ave["Condition"], y = df_ave["Read-out"]))
fig.show()

Strip graph example
Scatter plot example

Additionally, if there newly exists any convenient way to add significance indicators, that would be fantastic!

You know, I swear I tried this, but I suppose I must have missed it. This can be fixed, very simply, but including stripmode = “overlay” in the arguments for px.strip; subsequently, go.Box is appended overtop the original traces.

fig = px.strip(df, x = "Condition", y = "Read-out", stripmode = "overlay")