1

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}....}

1 Answer 1

3

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()
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much Nipun, that's exactly what I needed help with. Good luck with your PhD.
Now I want to create a scatter plot with the data above.. What I want to do is plot the x and y data, and title becomes a legend(key on the map). so for example, lets start with title1, plot data associated with title1 in red( or any color), and make a key saying "title1" is that color, then plot2 and associated data with different color...and so on. Any suggestions?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.