我想画一个条形图。x轴上是顾问的ID。它们的范围在1000到2000之间。每个顾问都有特定数量的客户(y轴)。在
现在我要绘制一个条形图。但是计划性地命令顾问id升序并将它们解释为整数,但它们不是。他们应该像我计划好的名单一样被安排。在
顺便说一下,在matplotlib中,顺序是正确的。在
trace1 = go.Bar(
x=consultants,
y=info[0,:]
)
trace2 = go.Bar(
x=consultants,
y=info[1,:],
)
trace3 = go.Bar(
x=consultants,
y=info[2,:]
)
trace4 = go.Bar(
x=consultants,
y=info[3,:]
)
data = [trace1, trace2, trace3, trace4]
layout = go.Layout(
barmode='stack',
xaxis=dict(
categoryorder='array',
categoryarray=consultants,
titlefont=dict(
size=18,
color='black'),
showticklabels=True,
tickfont=dict(
size=16,
color='black',
),
tickangle=20
),
yaxis=dict(
title='Number of customers',
titlefont=dict(
size=18,
color='black'),
showgrid=True,
showline=False,
showticklabels=True,
tickfont=dict(
size=16,
color='black')
),
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='stacked-bar')
有趣的是,似乎故意忽略了整数的} 来实现排序的禁用。在
categoryorder
,但是可以通过在xaxis
中传递layout
中的^{相关问题 更多 >
编程相关推荐