Add the mean in box plots with plotly express?

Hi!

I have the following figure:

Box plot from plotly express

and I would like to add the mean.

Is it possible with Plotly Express, without using Graph Objects go.Box()?

For information, here is my code:


import plotly.express as px
fig = px.box(device_field_strength_impact_df, 
	    y='value',
		x='device_field_strength', 
		color='variable', 
		# boxmean=True,
		facet_col='group',
		)
fig.show()

and the pandas DataFrame:


method	group	patient	device_field_strength	variable	value
expert1	experts	62	device_field_strength_1.5	F1_score	0.857
expert1	experts	66	device_field_strength_3	    F1_score	0.909
...	...	...	...	...	...	...

Note: I made the same figure with Graph Objects but I donโ€™t know how to handle the legend and x labels.

You can add the averages by adding, after the graph, the settings for the averages you have already tried.

fig = px.box(...) 
fig.update_traces(boxmean=True)
fig.show()
1 Like

Wow! That was easy! It should be added in the documentationโ€ฆ Thanks!

1 Like