python plot a dictionary 1

python plot a dictionary

# credit to the Stack Overflow user in the source link

import matplotlib.pylab as plt

lists = sorted(d.items()) # sorted by key, return a list of tuples

x, y = zip(*lists) # unpack a list of pairs into two tuples

plt.plot(x, y)
plt.show()

Here is what the above code is Doing:
1. We sort the dictionary by key, and then unpack the key and value into two tuples.
2. We then plot the x and y values.

Similar Posts