简体   繁体   中英

plotly vs seaborn: violin plot in python

I tried to plot violin plot in plotly and observed that plotly scales the data according to the width and not to area of each category. This scale parameter can be controlled in a seaborn library, but not in plotly. Is there a way to scale the violins according to the area in plotly as it is done in seaborn?

#plotly    
fig = ff.create_violin(flats, data_header='rent', group_header='type', width =900, height=600, )
#seaborn    
sns.violinplot(y='rent',x='type',data=flats,ax = axes, scale='area')

plotly plotly

seaborn seaborn

I don't know an easy way to do it but it can be done. If you print fig you see that each violin has a range in the layout. The range value is defined according to the violin itself. If you set the same range value for all violin, then you get what you want :

for name,axi in fig['layout'].items():
    if name[:4] == 'xaxi':
        axi['range'] = [-1,1]

Of course [-1,1] should be changed to fit your data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM