From a2a6c67f9777c3b07535f0b401d7f6b4a122ceaa Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 8 Jan 2013 12:32:10 +0100 Subject: scripts: plotcsv.py: Also plot linear and cubic interpolation of data --- scripts/plotcsv.py | 11 +++++++++-- 1 file 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) -- cgit v1.2.3-54-g00ecf