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

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

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",
    }
    )`

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

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

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

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'})

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:

确定