It looks great, but let’s pretend I am unhappy with the widths of the boxrs and want to make them wider/smaller by using fig.update_traces(width=0.5). The result:
Suddenly, the boxmode="group" is ignored. Is this a bug? Or is there another way to change the width of box plots while still retaining grouping?
Based on this SO thread from 2014 I tried to set fig.update_layout(boxgroupgap=1) and fig.update_layout(boxgap=1), but neither made any difference here.
Thanks for the reply, but no. My goal is indeed to change the width of the boxes independent of the figure width. Combining box width and figure width does not help either:
I get it now. I tried to change the width by fig.update_traces(width=0.5) and additionally set different values of boxgroupgap and boxgap in my tests. This does not work.
The trick seems to be to only use boxgroupgap and boxgap to indirectly set the width by specifiying the gaps. As soon as fig.update_traces(width=0.5) is added, the grouping is lost.
Hey Michael! I am facing the same problem apparently. As you can see in my figure,
there is a huge gap between each group of boxes and I tried every way to reduce it and make it look better.
Hi @Mauz a small follow up. I tried to omit the gaps using plotly.graph_objects. I admit, that this solution is quite laborious and far from perfect but it might work as a stating point for you.
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import pandas as pd
import plotly.express as px
import numpy as np
# set number of categories
cat_num = 5
# set number of types
type_num = 20
# create data
categories = []
for i in range(1, cat_num + 1):
categories.extend…