Hi,
so I was using “grouped” + “violin plot” + “positive side only” to compare distributions. And was trying to remove some white spaces between distributions. So here’s an example.
below is when “both” sides are plotted (with side
option),
below is when “positive” sides are plotted (with side
option),
and I basically want to remove those whitespaces that resulted in by switching “both” to “positive” (like the space between green and red and the space between red and blue) so that I can enlarge/scale-up the distributions in the figure . I found another way to present what I want by using “overlay” violinmode (instead of “group”) but also wanted to know if removing those whitespaces are possible with the “group” violinmode. Below is the sample code that can generate the figures above. Would appreciate some insights, thank you!
##############################
# which side of the distribution
##############################
side='positive'
##############################
# generating sample data
##############################
df_test = pd.DataFrame()
for xval in ['x','y','z']:
temp = pd.DataFrame()
temp['yaxis'] = np.random.normal(10, 1, 1000)
temp['xaxis'] = xval
df_test = pd.concat([df_test, temp])
fig = go.Figure()
##############################
# a
##############################
fig.add_trace(go.Violin(
x=df_test['yaxis'],
y=df_test['xaxis'],
orientation='h',
legendgroup='a',
scalemode='width',
scalegroup=f"a_{basis}",
name='a',
side=side,
points=False,
box_visible=False,
))
##############################
# b
##############################
fig.add_trace(go.Violin(
x=df_test['yaxis'],
y=df_test['xaxis'],
orientation='h',
legendgroup='b',
scalemode='width',
scalegroup=f"b_{basis}",
name='b',
side=side,
points=False,
box_visible=False,
))
##############################
# a
##############################
fig.add_trace(go.Violin(
x=df_test['yaxis'],
y=df_test['xaxis'],
orientation='h',
legendgroup='c',
scalemode='width',
scalegroup=f"c_{basis}",
name='c',
side=side,
points=False,
box_visible=False,
))
##############################
# Plot setting
##############################
fig.update_yaxes(
tickson='boundaries',
showgrid=True,
gridwidth=1,
gridcolor='rgb(200,200,200)',
)
fig.update_layout(
violinmode='group',
violingap=0,
violingroupgap=0,
width=600,
height=500,
margin=dict(
l=0,
r=0,
t=0,
b=0
),
plot_bgcolor='white'
)
fig.show()