我有一系列X轴刻度标签,通过以下方式将它们放在绘图上:
plt.figure(1)
ax = plt.subplot(111)
ax.bar(Xs, Ys, color="grey",width=1)
ax.set_xticks([i+.5 for i in range(0,count)])
ax.set_xticklabels(Xlabs, rotation=270)
现在我想根据标签内容对每个标签进行着色。例如: 我想使用规则“如果是1,则将标签着成红色,如果是0,则将标签着成蓝色”,类似于这样:
colors = ['blue','red']
ax.set_xticklabels(Xlabs, rotation=270, color = [colors[i] for i in Xlabs])
但那是无效的。有没有办法我能实现这个?