[英]Dash Plotly multiple y Axis
I have the following Dataframe: Dataframe我有以下数据框:数据框
I want to plot it into a bar chart.我想将它绘制成条形图。 With 3 bars, 1 for Positive, 1 for Neutral and 1 for Negative.
有 3 根柱线,1 根柱线,1 根柱线,1 根柱线柱。 Im trying this:
我正在尝试这个:
fig = px.bar(senti_df, x=senti_df.index, y=['Positive', 'Neutral', 'Negative'])
fig.show()
But all I get as a result is this: Output但我得到的结果是:输出
How can I plot them side by side?如何将它们并排绘制? And is there a possibility to plot it into a pie chart?
是否有可能将其绘制成饼图? Thank you so much for your help, I'm a beginner :(
非常感谢您的帮助,我是初学者:(
I'd like to use raw-like data, therefore, we have some transformation via melt()
我想使用类似原始的数据,因此,我们通过
melt()
进行了一些转换
df = pd.DataFrame({'Positive':[17], 'Neutral':[26], 'Negative':[7], 'Währung':['Bitcoin(BTC)']})
df2 = df.melt(value_vars=['Positive','Neutral','Negative'], id_vars=['Währung'], var_name='connotation')
print(df2)
Währung connotation value
0 Bitcoin(BTC) Positive 17
1 Bitcoin(BTC) Neutral 26
2 Bitcoin(BTC) Negative 7
Plot bar chart绘制条形图
fig_bar = px.bar(df2, x='Währung', y='value', color='connotation', barmode='group')
fig_bar.show()
Plot pie chart绘制饼图
fig_pie = px.pie(df2, values='value', names='connotation')
fig_pie.show()
You can do this by adding the parameter barmode='group'
:您可以通过添加参数
barmode='group'
来做到这一点:
fig = px.bar(senti_df, x='Währung', y=['Positive', 'Neutral', 'Negative'], barmode='group')
Output:输出:
barmode (str (default 'relative')) – One of 'group', 'overlay' or 'relative' In 'relative' mode, bars are stacked above zero for positive values and below zero for negative values.
barmode (str (default 'relative')) -- 'group'、'overlay' 或 'relative' 之一 在'relative' 模式下,柱形堆叠在零之上表示正值,低于零表示负值。 In 'overlay' mode, bars are drawn on top of one another.
在“叠加”模式下,条形图相互叠加。 In 'group' mode, bars are placed beside each other.
在“组”模式下,条形图彼此并排放置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.