df = px.data.tips() fig = px.violin(df, y="tip", color="sex", violinmode='overlay', # draw violins on top of each other # default violinmode is 'group' as in example above hover_data=df.columns) fig.show()
for day in days: fig.add_trace(go.Violin(x=df['day'][df['day'] == day], y=df['total_bill'][df['day'] == day], name=day, box_visible=True, meanline_visible=True))
for i inrange(0,len(pd.unique(df['day']))): fig.add_trace(go.Violin(x=df['day'][(df['sex'] == 'Male') & (df['day'] == pd.unique(df['day'])[i])], y=df['total_bill'][(df['sex'] == 'Male')& (df['day'] == pd.unique(df['day'])[i])], legendgroup='M', scalegroup='M', name='M', side='negative', pointpos=pointpos_male[i], # where to position points line_color='lightseagreen', showlegend=show_legend[i]) ) fig.add_trace(go.Violin(x=df['day'][(df['sex'] == 'Female') & (df['day'] == pd.unique(df['day'])[i])], y=df['total_bill'][(df['sex'] == 'Female')& (df['day'] == pd.unique(df['day'])[i])], legendgroup='F', scalegroup='F', name='F', side='positive', pointpos=pointpos_female[i], line_color='mediumpurple', showlegend=show_legend[i]) )
# update characteristics shared by all traces fig.update_traces(meanline_visible=True, points='all', # show all points jitter=0.05, # add some jitter on points for better visibility scalemode='count') #scale violin plot area with total count fig.update_layout( title_text="Total bill distribution<br><i>scaled by number of bills per gender", violingap=0, violingroupgap=0, violinmode='overlay') fig.show()
import plotly.graph_objects as go from plotly.colors import n_colors import numpy as np np.random.seed(1)
# 12 sets of normal distributed random data, with increasing mean and standard deviation data = (np.linspace(1, 2, 12)[:, np.newaxis] * np.random.randn(12, 200) + (np.arange(12) + 2 * np.random.random(12))[:, np.newaxis])