Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting histogram on python with dictionary [duplicate]

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}
like image 659
Mohit Avatar asked Feb 07 '26 23:02

Mohit


2 Answers

You can simply use:

plt.bar(data.keys(), data.values())

enter image description here

like image 159
yatu Avatar answered Feb 09 '26 11:02

yatu


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)
like image 20
blue_note Avatar answered Feb 09 '26 12:02

blue_note