Last active
August 29, 2015 13:57
-
-
Save x/9552782 to your computer and use it in GitHub Desktop.
Generate a Histogram from a CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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