import matplotlib.pyplot as plt import numpy as np import sys from scipy.interpolate import spline
filename = sys.argv[1]
I take data from a file, y=time,x=distance
load it into 2 numpy arrays x and y
x,y=np.loadtxt(filename, delimiter=',', unpack=True)
dydx=np.zeros([1,len(x)],dtype = float)
zero = np.array(np.zeros(5))
xdiff = np.array([0,len(x)-1],dtype = float)
ydiff = np.array([0,len(x)-1],dtype = float)
xdiff = np.diff(x)
ydiff = np.diff(y)
dydx = np.divide(np.diff(x),np.diff(y))
plt.ylabel("Velocity")
plt.xlabel("Time")
a = np.linspace(y[0],y[len(y)-1],len(y))
dydx = np.append(dydx, zero[0])
The graph that I get is still pointy and not smooth
This is something I did to smoothen the plot but hasn't worked, still pointy
a_smooth = np.linspace(a.min(),a.max(),len(y))
dydx_smooth = spline(a,dydx,a_smooth)
this is the normal procedure for plotting
plt.plot(a_smooth,dydx_smooth)
plt.grid()
plt.show()
I tried to use splrev,splrep but the knots are not non-decreasing, the dydx constantly goes above and below zero, so that cannot be used. I saw the technique in a youtube video,it worked for him but not for me https://www.youtube.com/watch?v=uSB8UBrbMfk
you can get my input data from here https://pastebin.com/44Kn2sm5