如何在Plotly中创建百分比堆叠的条形图?
我有此代码,但想创建一个堆叠的%条形图。我该怎么做?
fig = px.bar(df, x='date', y=['var1','var2','var3', 'var4'],barmode='stack')
fig.show()
I have this code but want to create a stacked % bar chart. How would I do that?
fig = px.bar(df, x='date', y=['var1','var2','var3', 'var4'],barmode='stack')
fig.show()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您应该制作一个新列来计算每个
var
的%
,然后使用它来部署图表。请参考我的下面代码:这是输出:

I think you should make a new column that calculate
%
of eachvar
and then use it to deploy chart. Please refer my below code:And here is the Output:
