Reputation: 405
I'm struggling with the following problem in Python:
I got two dictionaries and I want to achieve a special plot using matplotlib.pylab. The dictionaries got the same length and holding the same keys in the same order, but holding different values for each of these keys. All keys and all values are integers.
I want to achieve a plot, where the x-axis shows the keys, in my case this would be 0 to 200, and the y axis should be some kind of histogram where for every x i want to display both values of the dictionary entries related to this x.
I think histogram ist the wrong word here, because in that case we would talk about a distribution. But this is not the case. I just want to display the value of both dicts for each key.
Any ideas?
Upvotes: 1
Views: 56
Reputation: 7293
You can iterate simultaneously on both your dictionaries like this:
for key in sorted(dict1.keys()): # iterkeys() in Python2
value1 = dict1[key]
value2 = dict2[key]
plot(key, value1)
plot(key, value2)
Upvotes: 1