python - Smoothing of graph gives a huge difference in the range -
i trying plot smooth curve using x,y cordinates above. howsoever graph out of range of data. snippet of code here.
import numpy np import matplotlib.pyplot plt scipy.interpolate import spline ylist = [0.36758563074352546, 0.27634194831013914, 0.22261484098939929, 0.10891089108910891, 0.31578947368421051, 0.086956521739130432, 0.27272727272727271, 0.18181818181818182, 0.0, 0.0, 0.92000000000000004, 0.0, 0.10526315789473684, 0.23333333333333334] xlist = [0.025000000000000001, 0.075000000000000011, 0.125, 0.17500000000000002, 0.22500000000000001, 0.27500000000000002, 0.32500000000000001, 0.375, 0.42500000000000004, 0.47500000000000003, 0.52500000000000002, 0.57500000000000007, 0.625, 0.97500000000000009] xlist_smooth = np.linspace(xlist.min(), xlist.max(), 100) ylist_smooth = spline(xlist, ylist, xlist_smooth) plt.plot(xlist_smooth,ylist_smooth)
i following curve output
i think problem here spline interpolation of higher order not suitable smoothing data.
below plotted spline interpolations of order 0 3. see once demand continuity of derivative (order 2 , higher) run problems last 2 points.
i guess choosing spline interpolation not choice here. interpolation assumes there no measurement errors , seem have clear outlier in data.
depending on want here, fitting piecewise continuous spline (order=1) may fine you. otherwise have different smoothing strategy.
import numpy np scipy.interpolate import spline import matplotlib.pyplot plt ylist = [0.36758563074352546, 0.27634194831013914, 0.22261484098939929, 0.10891089108910891, 0.31578947368421051, 0.086956521739130432, 0.27272727272727271, 0.18181818181818182, 0.0, 0.0, 0.92000000000000004, 0.0, 0.10526315789473684, 0.23333333333333334] xlist = [0.025000000000000001, 0.075000000000000011, 0.125, 0.17500000000000002, 0.22500000000000001, 0.27500000000000002, 0.32500000000000001, 0.375, 0.42500000000000004, 0.47500000000000003, 0.52500000000000002, 0.57500000000000007, 0.625, 0.97500000000000009] xlist_smooth = np.linspace(min(xlist), max(xlist), 100) fig, axes = plt.subplots(4,1, sharex=true) order, ax in enumerate(axes): ylist_smooth = spline(xlist, ylist, xlist_smooth, order=order) ax.plot(xlist_smooth, ylist_smooth, label="spline order %s" % order) ax.scatter(xlist, ylist, label="knots") ax.set_ylim(min(xlist)-1,max(xlist)+1) ax.legend()
Comments
Post a Comment