Adding shifted data set to data set - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Adding shifted data set to data set (/thread-35837.html) |
Adding shifted data set to data set - xquad - Dec-21-2021 Hello, I have a data set that I have shifted by a certain amount. The unshifted and shifted data set are plotted as you can see in the attached figure. using ... plt.plot(t+fwhm, Vs/np.max(Vs), color='r') plt.plot(t, Vs/np.max(Vs))how can the sum of the shifted and unshifted data set be plotted? Both t and Vs datasets are of type <class 'numpy.ndarray'>. Regards, xquad RE: Adding shifted data set to data set - xquad - Dec-22-2021 I tried: import matplotlib.pyplot as plt from scipy import interpolate x = t y = Vs f = interpolate.interp1d(x, y, fill_value = 'extrapolate') xnew = t + fwhm ynew = f(xnew) plt.plot(x, y, 'o', xnew, ynew, 'k') plt.xlim(-0.25e-7, 0.25e-7) plt.show()but the interpolated data will not be shifted... RE: Adding shifted data set to data set - xquad - Dec-22-2021 ah found it: xnew = t + fwhm print(np.max(xnew), np.max(t)) ynew = f(xnew) # use interpolation function returned by `interp1d` print(np.argmax(ynew), np.argmax(y)) plt.plot(x, y) plt.plot(x, ynew, 'r') plt.plot(x, y+ynew) plt.xlim(-0.25e-7, 0.25e-7) plt.show()its visible shifted if plotted on the same axis. (I found it after noticing a difference in np.argmax()) RE: Adding shifted data set to data set - Larz60+ - Dec-22-2021 Thanks for sharing the solution. |