显示px.bar从最大值到最小值

问题描述 投票:0回答:1

我已经使用plotly express 显示了数据框的一列。数据在 (0,80) 范围内,因此 我在这些值之间做了分类。 我想从 80 到 0 显示它们,但是

update_xaxes(categoryorder = '总计降序')

不适合我。 有人可以帮我吗? 我在 github 中发现了一个 2022 年以来仍然未解决的问题:

https://github.com/plotly/plotly.py/issues/3645

counts, bins = np.histogram(df.Age, bins=range(0, 80, 5))
bins = 0.5 * (bins[:-1] + bins[1:])

fig = px.bar(x=bins, y=counts, text_auto=True, labels={'x':'Age', 'y':'count'}, title = 'Age distribution between min (18) and max(69)' )
fig.update_xaxes(categoryorder = 'total descending')
fig.update_traces(textfont_size=14, textangle=0, textposition="outside", cliponaxis=False)
fig.show()

我也尝试过按降序对值进行排序,但也不起作用:

dfAge = df.Age.sort_values(ascending = False)
print(dfAge)
counts, bins = np.histogram(dfAge, bins=range(0, 80, 5))
bins = 0.5 * (bins[:-1] + bins[1:])

fig = px.bar(x=bins, y=counts, text_auto=True, labels={'x':'Age', 'y':'count'}, title = 'Age distribution between min (18) and max(69)' )
fig.update_traces(textfont_size=14, textangle=0, textposition="outside", cliponaxis=False)
fig.show()
dataframe express plotly histogram
1个回答
0
投票

我已经倒置了垃圾箱并且它有效,但我真的很想知道为什么选择这个选项

fig.update_xaxes(categoryorder = 'total descending')

不适合我。

© www.soinside.com 2019 - 2024. All rights reserved.