I want to plot the following dictionary on python using matplotlib.pyplot as a histogram. How can I code it up?
{'G': 198, 'T': 383, 'C': 260, 'A': 317}
I want to plot the following dictionary on python using matplotlib.pyplot as a histogram. How can I code it up?
{'G': 198, 'T': 383, 'C': 260, 'A': 317}
The histogram would be needed if you did not know the frequency of each item. That is, if you had data of the form
G G T G C A A T G
Since you already know the frequencies, it is just a simple bar plot
{'G': 198, 'T': 383, 'C': 260, 'A': 317}
labels, values = zip(*data.items())
plt.bar(labels, values)
With pandas:
d = {'G': 198, 'T': 383, 'C': 260, 'A': 317}
df = pd.DataFrame({x:[y] for x,y in d.iteritems()}).T
df.plot(kind='bar')
plt.show()