使用字典值为直方图的一部分着色

时间:2016-08-26 11:11:53

标签: python dictionary matplotlib colors histogram

dic={-0.018273:"cluster0",0.473295:"cluster2",30.07545:"cluster1",0.05741:"cluster0"}

如果我的字典如上所述,但有很多元素,我使用下面的python代码来绘制它

import matplotlib.pyplot as plt
plt.hist(data.keys(),bins=20)
plt.show()

我得到一个单色的直方图。 但我想要一个如下所示的直方图 enter image description here

颜色对应于字典的值

例如: 红色代表cluster0和 blue代表cluster1

我应该对代码做出哪些更改?

0 个答案:

没有答案