[英]Plot group bar chart plotly python
df.reset_index(inplace=True)
df.rename(columns={'index': 'group'}, inplace=True)
df
##
group API1 API2 API3
0 s1 41 56 48
1 s2 40 50 45
2 s3 15 24 8
df_plot = df.melt(value_vars=df.columns, id_vars='group')
df_plot
###
group variable value
0 s1 API1 41
1 s2 API1 40
2 s3 API1 15
3 s1 API2 56
4 s2 API2 50
5 s3 API2 24
6 s1 API3 48
7 s2 API3 45
8 s3 API3 8
Plot
fig = px.histogram(df_plot, x='variable', y='value', color='index', barmode='group')
fig.show()
fig2 = px.histogram(df_plot, x='variable', y='value', color='index')
fig2.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.