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}
You can simply use:
plt.bar(data.keys(), data.values())

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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With