我有一系列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])
但那是无效的.有什么办法可以实现吗?