Skip to content

Instantly share code, notes, and snippets.

@x
Last active August 29, 2015 13:57
Show Gist options
  • Save x/9552782 to your computer and use it in GitHub Desktop.
Save x/9552782 to your computer and use it in GitHub Desktop.
Generate a Histogram from a CSV
#! /usr/bin/python
from matplotlib import pyplot as plt
import sys
if len(sys.argv) != 5:
print 'Usage: ./csv_to_histogram.py [INPUT CSV] [OUTPUT PNG] [TARGET COL] [NUM BINS]'
sys.exit(1)
in_fname = sys.argv[1]
out_fname = sys.argv[2]
col = int(sys.argv[3])
num_bins = int(sys.argv[4])
vals = []
with open(in_fname) as f:
for line in f.read().splitlines():
vals.append(float(line.split(', ')[col]))
plt.hist(vals, bins=num_bins)
plt.savefig(out_fname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment