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)
添加回答
举报