我有以下数据框:
key1 key2 key3 ...
time
Jan 0.5 0.4 0.2 ...
Feb 0.3 0.4 0.4 ...
Mar 0.2 0.4 0.1 ...
Apr 0.5 0.3 0.8 ...
... ... ... ...
我创建了条形图,如下所示:
import matplotlib.pyplot as plt
ax = df10.plot(kind='bar', figsize=(15, 10), fontsize=12, stacked='true')
plt.show()
这给了我一个堆积的条形图,其中包含许多条形和多种颜色,乍一看并不能提供一个很好的概述。 因此,我只想突出显示那些会产生影响的栏(> 0.5),并隐藏不重要的栏(通过将它们涂成灰色)。
因此,目标是一些有条件的着色:值低于0.5的条应以灰色着色,其余应使用预定义的颜色。
我尝试了很多方法,却找不到有效的解决方案。我是python / matplotlib的新手。 谁能帮我吗?提前非常感谢您,任何帮助将不胜感激!
You could loop through all the patches of the ax, check whether they are a
Rectangle
and change the color depending on some condition.