【发布时间】:2020-04-13 06:22:12
【问题描述】:
我有一个数据集,其中包含一个名为x 的列表中的datetime.datetime 对象和一个名为y 的整数列表。我像这样绘制它们:
plt.bar(x, y)
plt.show()
在给定日期之后,我将如何为所有条形着色另一种颜色?我知道我可以通过分配plt.bar(x, y) 的结果来获得条形列表,但除了制作简单的绘图之外,我从来没有搞乱过matplotlib。
【问题讨论】:
-
例如
colors = ['b' if xi < x_special else 'r' for xi in x]然后plt.bar(x, y, color=colors)? -
这能回答你的问题吗? Matplotlib different colors for bar graph based on value(见第二个答案)
标签: python matplotlib python-datetime