matplotlib bar chart from dictionary 1

matplotlib bar chart from dictionary

a_dictionary = {"a": 1, "b": 2, "c": 3}
keys = a_dictionary.keys()
values = a_dictionary.values()

plt.bar(keys, values)
# plots bar chart of keys (x) against values (y)

Here is what the above code is Doing:
1. Create a dictionary with three key-value pairs
2. Get the keys and values from the dictionary
3. Plot the keys against the values

Similar Posts