Thursday 19 March 2015

A simple plot using input from a text file

I am continuing from my last blog on using matplotlib for creating charts. Here is another simple example, but this time reading data from a text file.

I have created a text file as seen below in the same directory where my python scripts are saved. Since I am using anaconda they are usually saved in the documents folder.


I have not included any heading to the columns in my input file, my intention is to just create a list and plot them. I have just included X values in first column and Y values in the second. I am just going to transpose them and assign them to a single variable and plot them.

I think this can be better put in a scatter plot, so I am using same matplotlib library as in my previous blog and numpy for loading text and using transpose options.

The code can be written as seen below.





This would give and output like this when executed.
































Again this can be extended to create more sensible and useful visualizations.

No comments:

Post a Comment