Change box width in grouped box plot

How can the width and spacing of a plotly box plot (e.g. px.box) be changed? Code example:

import pandas as pd
import plotly.express as px
df = pd.DataFrame({
    "val":  [ 1,  2,  1,  3,  1,  4,  3,  2,  2,  3,  3,  0],
    "cat1": ["A","A","A","A","B","B","B","B","C","C","C","C"],
    "cat2": ["X","X","Y","Y","X","X","Y","Y","X","X","Y","Y"]
})
fig=px.box(df,
           x="cat1",
           y="val", 
           color="cat2",
           boxmode="group")
fig.show()

Produces this nice plot:


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.

Version: plotly 4.12.0