AttributeError: ‘Figure’对象没有’sort_values’属性。

huangapple go评论108阅读模式
英文:

AttributeError: 'Figure' object has no attribute 'sort_values'

问题

我正在为我的工作做数据分析页面,一直在尝试将这个条形图的格式改成升序。我正在使用GitHub和Streamlit将信息部署到网页上。

这是我用来创建实际条形图的代码片段:

  1. figBARChartJune = px.bar(df_table, x="Issue Sub-Type", y="June 2023", text_auto=True)
  2. figBARChartJune.update_traces(marker_color=['#12e195', '#01cdfe', '#05ffa1', '#b967ff', '#fffb96',
  3. '#001eff', '#e377c2', '#d05037', '#bcbd22', '#17becf',
  4. '#00FFFF', '#BFFF00'])
  5. figBARChartJune.update_layout(
  6. xaxis_title="Issue Sub-Types",
  7. yaxis_title="Number of Issues",
  8. legend_title="Issue Sub-Types",
  9. font=dict(
  10. family="Times New Roman, monospace",
  11. size=12,
  12. color="RebeccaPurple"
  13. ),
  14. title={
  15. 'text': "Total Number of Issues for June 2023",
  16. }
  17. )

条形图

迄今为止,没有任何方法可以使条形图按升序显示。我将数字文本放在条的上方以显示确切的数量。

请帮忙?

谢谢!

英文:

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:

  1. figBARChartJune = px.bar(df_table, x="Issue Sub-Type", y="June 2023", text_auto=True)
  2. figBARChartJune.update_traces(marker_color=['#12e195', '#01cdfe', '#05ffa1', '#b967ff', '#fffb96',
  3. '#001eff', '#e377c2', '#d05037', '#bcbd22', '#17becf',
  4. '#00FFFF', '#BFFF00'])
  5. figBARChartJune.update_layout(
  6. xaxis_title="Issue Sub-Types",
  7. yaxis_title="Number of Issues",
  8. legend_title="Issue Sub-Types",
  9. font=dict(
  10. family="Times New Roman, monospace",
  11. size=12,
  12. color="RebeccaPurple"
  13. ),
  14. title={
  15. 'text': "Total Number of Issues for June 2023",
  16. }
  17. )`

Bar graph

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

这是因为条形图本身只是按提供的数据绘制。默认情况下,它不是帕累托(有序的)。

您可以通过以下方式设置此行为:

  1. fig.update_layout(xaxis={'categoryorder':'total descending'})

或者替代地:

  1. 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

  1. fig.update_layout(xaxis={'categoryorder':'total descending'})

or alternatively

  1. fig.update_layout(xaxis={'categoryorder':'total ascending'})

https://plotly.com/python/bar-charts/

huangapple
  • 本文由 发表于 2023年7月6日 21:38:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76629460.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定