diff options
-rwxr-xr-x | scripts/plotcsv.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/scripts/plotcsv.py b/scripts/plotcsv.py index 32e96c5..931e4e8 100755 --- a/scripts/plotcsv.py +++ b/scripts/plotcsv.py @@ -3,6 +3,7 @@ import csv import getopt import os, sys +import scipy.interpolate import numpy as np import matplotlib.pyplot as plt @@ -16,12 +17,18 @@ def read_and_plot_csv(csv_file, x_max=X_MAX, y_max=Y_MAX): reader = csv.reader(open(csv_file, 'r'), delimiter=',') x_name,y_name = reader.next() # header line - X = np.array([ [ float(_x), float(_y) ] for _x,_y in reader ]) + X = np.array([[float(_x), float(_y)] for _x,_y in reader ]) x = X[:,0] y = X[:,1] + # interpolate data points + xnew = np.linspace(min(x), max(x), len(x)*5) + f = scipy.interpolate.interp1d(x, y) + f2 = scipy.interpolate.interp1d(x, y, kind='cubic') + fig = plt.figure() - plt.plot(x, y) + plt.plot(x, y, 'o', xnew, f(xnew), '-', xnew, f2(xnew), '--') + plt.legend(['data', 'linear interp.', 'cubic interp.'], loc='best') plt.axis([0, x_max, 0, y_max], 'equal') plt.xlabel(x_name) plt.ylabel(y_name) |