Skip to content

Instantly share code, notes, and snippets.

@fcostin
Created July 12, 2011 11:40
Show Gist options
  • Save fcostin/1077817 to your computer and use it in GitHub Desktop.
Save fcostin/1077817 to your computer and use it in GitHub Desktop.
Plot x,y pairs from csv file.
"""
Plot x,y pairs from csv file.
usage:
python plot_csv.py xy_data.csv
csv format:
assume no header row
assume rows are form "123.0,456.0\n" etc
"""
import csv
import pylab # see http://matplotlib.sourceforge.net/
import sys
def main():
if len(sys.argv) != 2:
print 'usage: python plot_csv.py xy_data.csv'
sys.exit(1)
xs = []
ys = []
with open(sys.argv[1], 'r') as f:
reader = csv.reader(f, delimiter = ',')
for row in reader:
xs.append(float(row[0]))
ys.append(float(row[1]))
pylab.figure()
pylab.title('x versus y : the final reckoning')
pylab.scatter(xs, ys, label = 'extremely helpful data points')
pylab.legend(loc = 'upper left')
pylab.xlabel('x')
pylab.ylabel('y')
pylab.show() # delete this to run in batch mode (saving many figs etc)
# you can save em too
# pylab.savefig('plot.png')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment