I have created a basic bar chart in plotly that I would like to sort by descending order.
我找不到在绘图语法中指定这一点的简单方法,因此我尝试使用 Pandas 修改数据框。这也没有奏效。
我的代码如下:
import plotly.plotly as py
import plotly.graph_objs as go
import pandas as pd
df = pd.read_csv('C:/Users/Documents/Python/CKANMay.csv')
sd = df.nlargest(3,'Views')
fd = sd.sort_values(by='Views', ascending = False)
my_data = [go.Bar( x = fd.Views, y = fd.Publisher, orientation = 'h')]
my_layout = ({"title": "Most popular publishers",
"yaxis": {"title":"Publisher"},
"xaxis": {"title":"Views"},
"showlegend": False})
fig = go.Figure(data = my_data, layout = my_layout)
py.iplot(fig)
我想反转条形图,以便具有最大值的列位于顶部。感谢您的任何帮助。
添加这个来更新你的数字:
fig.update_layout(barmode='stack', xaxis={'categoryorder':'total descending'})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)