user3262210
user3262210

Reputation: 117

Plotting dictionaries within a dictionary in Myplotlib python

I need help plotting a dictionary, below is the data sample data set. I want to create a graph where x:y are (x,y) coordinates and title'x' would be the title of the graph.. I want to create individual graphs for each data set so one for title1':{x:y, x:y}, another one for title2:{x:y, x:y}....and so on.

Any help would be greatly appreciated. Thank you.

data = {'title1':{x:y, x:y},title2:{x:y,x:y,x:y},'title3':{x:y,x:y}....}

Upvotes: 1

Views: 6703

Answers (1)

Nipun Batra
Nipun Batra

Reputation: 11367

Creating sample data

In [3]: data = {'title1': {10:20, 4:10}, 'title2':{8:10, 9:20, 10:30}}

In [4]: data
Out[4]: {'title1': {4: 10, 10: 20}, 'title2': {8: 10, 9: 20, 10: 30}}

Iterating over data; creating x and y for each title and plotting it in new figure

In [5]: for title, data_dict in data.iteritems():
   ...:     x = data_dict.keys()
   ...:     y = data_dict.values()
   ...:     plt.figure()
   ...:     plt.plot(x,y)
   ...:     plt.title(title)

If you are not using IPython

plt.show()

Upvotes: 3

Related Questions