1
votes

I am trying to plot the data I have stored in a pandas DataFrame using plotly.express as a box plot. The df looks like the following:

enter image description here


This is my code for making the basic boxplot graph in plotly:

import plotly.express as px

fig = px.box(df1, x="Condition",
             y="Number of Groups")
fig.show()

Giving as a result the kind of graph I was looking for: enter image description here

Now, I wanna color each condition in a different color for what I use:

import plotly.express as px

fig = px.box(df1, x="Condition",
             y="Number of Groups",
             color="Condition")
fig.show()

Giving me this graph in which now the box plots are much narrower than normal. Does anybody knows how to avoid this? Thanks enter image description here

1

1 Answers

5
votes

This is a bug which has been fixed in version 4.8 of plotly and a workaround for versions below that is to add boxmode="overlay" inside the px.box() call when color is set to the same value as x. And I should add that the same applies to px.violin and px.strip plots with violinmode and stripmode, respectively :)