我想绘制一个条形图。在x轴上是顾问的ID。他们的范围在1000到2000之间。每位顾问都有特定数量的顾客(y轴)。图解停用x轴排序
现在我想绘制阴谋条形图。但是阴谋地命令顾问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')
看一看:https://plot.ly/python/reference/#layout-xaxis-categoryorder –
好像是分辩关键字。但是如果我输入categoryorder ='array'。类别阵列应该如何?它是列表(范围(len(num_consultants)))还是num_consultants。到现在为止,现在有效果。 – user47091