[英]Plotly: How to plot multiindex dataframe as stacked bar chart in Plotly?
[英]how to plot 100% bar chart from a stacked chart with plotly?
您好,我正在嘗試使用 plotly 在 streamlit 中使用 plotly 創建 100% 堆疊條形圖。我嘗試使用 relative 但無濟於事。
dfCategory = dfQuery.groupby(['l1_category_name','pricingPosition'])['pricingPosition'].count().reset_index(name="count")
fig = px.bar(dfCategory, x="count", y="l1_category_name", color='pricingPosition', orientation='h',
height=400)
fig.update_layout(barmode='relative')
st.plotly_chart(fig, use_container_width=True)
任何幫助將不勝感激
我認為Plotly中的'相對'模式是一個function來總結正面和負面,而不是百分比顯示。 直方圖 function 具有堆疊百分比的功能,也可以用百分比顯示。 這是官方參考中的示例。
import plotly.express as px
long_df = px.data.medals_long()
fig = px.bar(long_df, x="nation", y="count", color="medal", title="Long-Form Input")
fig.update_layout(barmode='relative')
fig.show()
import plotly.express as px
long_df = px.data.medals_long()
fig = px.histogram(long_df, x="nation",
y="count", color="medal",
barnorm='percent', text_auto='.2f',
title="Long-Form Input")
fig.show()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.