is it possible to have a combination group and split violin plot?
I can’t seem to figure out how to do this.
I’d like to be able to have multiple split violins per group in x.
is it possible to have a combination group and split violin plot?
I can’t seem to figure out how to do this.
I’d like to be able to have multiple split violins per group in x.
Hi @juls858 welcome to the forum! You can have only one violinmode
in the layout
so you cannot have both overlay
(which you need to make split violin plot) and group
. However, what you can do is to use multicategory axes to group several split plots with the same label. I quickly adapted the example of the doc to show below how this can be done. Hope this helps!
import plotly.graph_objects as go
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/violin_data.csv")
fig = go.Figure()
days_yes = df['day'][ df['smoker'] == 'Yes']
grouped_labels_yes = days_yes.map({"Thur":"A", "Fri":"A", "Sat":"B", "Sun":"B"})
days_no = df['day'][ df['smoker'] == 'No']
grouped_labels_no = days_no.map({"Thur":"A", "Fri":"A", "Sat":"B", "Sun":"B"})
fig.add_trace(go.Violin(x=[grouped_labels_yes, days_yes],
y=df['total_bill'][ df['smoker'] == 'Yes' ],
legendgroup='Yes', scalegroup='Yes', name='Yes',
side='negative',
line_color='blue')
)
fig.add_trace(go.Violin(x=[grouped_labels_no, days_no],
y=df['total_bill'][ df['smoker'] == 'No' ],
legendgroup='No', scalegroup='No', name='No',
side='positive',
line_color='orange')
)
fig.update_traces(meanline_visible=True)
fig.update_layout(violingap=0, violinmode='overlay')
fig.show()
This works great thanks! Is there an easy way to hide a level of labels?