-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplot_csv_histogram.py
executable file
·32 lines (27 loc) · 1.1 KB
/
plot_csv_histogram.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python3
#
# Uses matplotlib to make a histogram from data in a CSV file.
import argparse
import sys
from os.path import splitext, basename
import pandas as pd
import matplotlib.pyplot as plt
if __name__ == '__main__':
ap = argparse.ArgumentParser(description='Plot time series from CSV, with time in first column')
ap.add_argument('csvfile', help='CSV file that contains a header with labels')
ap.add_argument('--title', help='Title of plot')
ap.add_argument('--xlabel', help='Label for x axis')
ap.add_argument('--ylabel', help='Label for y axis')
ap.add_argument('--columns', help='Keep only these column numbers')
args = ap.parse_args()
df = pd.read_csv(args.csvfile, header=0)
plt.figure()
for column in df:
plt.hist(df[column], bins=50, label=column)
plt.xlabel(args.xlabel or '')
plt.ylabel(args.ylabel or '')
plt.title(args.title or '')
plt.legend()
out_filename = '{}-hist.png'.format(splitext(basename(args.csvfile))[0])
plt.savefig(out_filename)
print('Wrote histogram to {}.'.format(out_filename), file=sys.stderr)