Given multiple CSV files containing a timestamp column and some plottable values (int or float) this script will plot multiple columns of data by time.
Usage is as such – ./CSVPlot.py first.csv second.csv third.csv
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#!/usr/bin/python import numpy from matplotlib import pyplot as plt from datetime import datetime import sys timestamps = [] legend = [] for arg in sys.argv[1:]: data=numpy.genfromtxt(arg, delimiter=",", dtype=None, names=True) for columnName, dataType in data.dtype.descr: if not isinstance(data[columnName][0], basestring): if columnName.strip() != 'timestamp': timestamps = [datetime.fromtimestamp(x) for x in data['timestamp']] plt.plot(timestamps, data[columnName]) legend.append(columnName) plt.legend(legend, loc='upper right') #plt.savefig('test.png') plt.xticks(rotation=70) plt.show() |
Questions? Comments?