summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2013-01-08 12:32:10 +0100
committerTobias Klauser <tklauser@distanz.ch>2013-01-08 12:32:10 +0100
commita2a6c67f9777c3b07535f0b401d7f6b4a122ceaa (patch)
treec267cb237306043ec077aae831fad652177798e4
parent424d5288e7dec59851dd0920dd10a5d261834b35 (diff)
scripts: plotcsv.py: Also plot linear and cubic interpolation of data
-rwxr-xr-xscripts/plotcsv.py11
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)