0

Hello I would like to graph the dictionary called: dictDistribution, I builded it as follows:

y_pred_list = y_pred.tolist()

dictDistribution={}
for i in set(y_pred_list):
    print("Number of elements in cluster "+str(i)+":",y_pred_list.count(i))
    dictDistribution[i]=y_pred_list.count(i)
#print(y_pred_list)
print(dictDistribution.get(0))

this dictionary contains numbers that are frecuences of labels I would like to perform a graph from this I tried:

import matplotlib.pyplot as plt
plt.bar(range(len(dictDistribution)), dictDistribution.values(), align='center')
plt.xticks(range(len(dictDistribution)), dictDistribution.keys())

plt.show()

However this work well but I am getting all in blue, I would like to add distinct colors to each bar, so I appreciate support with this,

neo33
  • 1,809
  • 5
  • 18
  • 41
  • i think the `plt.bar`as, the `plt.hist`, can return a list of bars. You could iterate either over a colormap or your own colors as suggested [here](http://stackoverflow.com/questions/23061657/plot-histogram-with-colors-taken-from-colormap) – Gene Burinsky Dec 29 '16 at 05:52
  • 1
    In brief, your question is answered [here](http://stackoverflow.com/questions/18973404/setting-different-bar-color-in-matplotlib-python) – Gene Burinsky Dec 29 '16 at 06:00

0 Answers0