【发布时间】:2020-12-24 20:43:21
【问题描述】:
如果您使用的是面向对象的方法,目前没有简单的方法可以在 matplotlib 中为特定条形设置特定颜色。
这引出了我的第二个问题,即 在 matplotlib 中绘制的最佳方法是什么(pyplot 一或 oop 一)?
我发现的一个 hack:
heights = x
labels = y
colors = ["dimgrey" for x in labels]
if np.isin(true_val, labels):
index = np.argmax(labels == true_val)
colors[index] = "green"
ax[3].bar(labels, heights, color=colors)
Pyplot方式:
barlist=plt.bar([1,2,3,4], [1,2,3,4])
barlist[0].set_color('r')
类似问题:
【问题讨论】:
标签: python matplotlib data-visualization jupyter