英文:
AttributeError: 'Figure' object has no attribute 'sort_values'
问题
我正在为我的工作做数据分析页面,一直在尝试将这个条形图的格式改成升序。我正在使用GitHub和Streamlit将信息部署到网页上。
这是我用来创建实际条形图的代码片段:
figBARChartJune = px.bar(df_table, x="Issue Sub-Type", y="June 2023", text_auto=True)
figBARChartJune.update_traces(marker_color=['#12e195', '#01cdfe', '#05ffa1', '#b967ff', '#fffb96',
'#001eff', '#e377c2', '#d05037', '#bcbd22', '#17becf',
'#00FFFF', '#BFFF00'])
figBARChartJune.update_layout(
xaxis_title="Issue Sub-Types",
yaxis_title="Number of Issues",
legend_title="Issue Sub-Types",
font=dict(
family="Times New Roman, monospace",
size=12,
color="RebeccaPurple"
),
title={
'text': "Total Number of Issues for June 2023",
}
)
迄今为止,没有任何方法可以使条形图按升序显示。我将数字文本放在条的上方以显示确切的数量。
请帮忙?
谢谢!
英文:
I am working on a data analysis page for my job and I have been trying to change the format of this bar graph to ascending order. I am using GitHub and Streamlit to deploy the information to a webpage.
This is the piece of code I used to create the actual bar graph:
figBARChartJune = px.bar(df_table, x="Issue Sub-Type", y="June 2023", text_auto=True)
figBARChartJune.update_traces(marker_color=['#12e195', '#01cdfe', '#05ffa1', '#b967ff', '#fffb96',
'#001eff', '#e377c2', '#d05037', '#bcbd22', '#17becf',
'#00FFFF', '#BFFF00'])
figBARChartJune.update_layout(
xaxis_title="Issue Sub-Types",
yaxis_title="Number of Issues",
legend_title="Issue Sub-Types",
font=dict(
family="Times New Roman, monospace",
size=12,
color="RebeccaPurple"
),
title={
'text': "Total Number of Issues for June 2023",
}
)`
Nothing has been working so far to display the bar graph in ascending order. I put the number text on the stems themselves to show the exact amount.
Please help?
Thanks
答案1
得分: 1
这是因为条形图本身只是按提供的数据绘制。默认情况下,它不是帕累托(有序的)。
您可以通过以下方式设置此行为:
fig.update_layout(xaxis={'categoryorder':'total descending'})
或者替代地:
fig.update_layout(xaxis={'categoryorder':'total ascending'})
https://plotly.com/python/bar-charts/
英文:
That is because the bar graph in itself just plots the data as provided. It is not by default a Pareto (ordered).
You can set this behavior by
fig.update_layout(xaxis={'categoryorder':'total descending'})
or alternatively
fig.update_layout(xaxis={'categoryorder':'total ascending'})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论