1 回答

TA貢獻1816條經驗 獲得超4個贊
用于此的正確鍵是layout.xaxis.categoryorder, 帶有值"total ascending",但它僅適用于layout.xaxis.typeis "category"。如果您的x數組包含字符串,這會自動發生,但如果您x只包含數字,則必須手動設置它。
這是barplot推薦的函數版本:
def barplot(x,y):
data = [go.Bar(
x=x,
y=y,
marker={
'color': y,
'colorscale': 'Reds'
}
)]
layout = {
'xaxis': {
'tickvals': x,
'ticktext': ['store ' + str(i) for i in x],
'tickangle': 40,
'type': "category",
'categoryorder': 'total ascending'
}
}
fig = go.FigureWidget(data=data, layout=layout)
return iplot(fig)
添加回答
舉報