Black Lives Matter. Please consider donating to Black Girls Code today.

Grouped and split violin plot possible?

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("")

fig = go.Figure()

days_yes = df['day'][ df['smoker'] == 'Yes']
grouped_labels_yes ={"Thur":"A", "Fri":"A", "Sat":"B", "Sun":"B"})
days_no = df['day'][ df['smoker'] == 'No']
grouped_labels_no ={"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',
fig.add_trace(go.Violin(x=[grouped_labels_no, days_no],
                        y=df['total_bill'][ df['smoker'] == 'No' ],
                        legendgroup='No', scalegroup='No', name='No',
fig.update_layout(violingap=0, violinmode='overlay')

This works great thanks! Is there an easy way to hide a level of labels?