1 year ago
#378300
Barry O'Keeffe
How to assign a specific point of a plotted function to a specific point of a graph
I have a series of waves plotted and I was wondering is there any way to create a plot such that the peak of each wave is at the same point so as better to see the difference between each wave.
Each wave is plotted as such with different input variables:
plt.plot(x0-X0,peta0)
plt.xlim(936-X0,995-X0)
The plt.xlim
is just to get each wave in the same reference frame.
I have the index of each peak if that helps in this solution.
Edit:
The waves plotted above are from quite a complex model and I cannot post the code here. However consider the following example:
x = np.linspace(0,500,2000)
eta = np.sin(2*x*np.pi/23) + np.sin(2*x*np.pi/28) + np.sin(2*x*np.pi/33)
peaks = [26,133,193,291,388,474,575,683,831,940,1039,1127,1227,1378,1488,1595,1695,1763,1861,1944]
troughs = [80,190,239,342,430,523,628,748,886,991,1083,1175,1281,1434,1542,1647,1725,1812,1905,1988]
Choosing to split at certain troughs of this wave and plotting these sections of the wave like this we get this plot with the peaks marked.
peak9 = peaks[9] - troughs[8]
peak10 = peaks[10] - troughs[9]
peak11 = peaks[11] - troughs[10]
peak12 = peaks[12] - troughs[11]
plt.plot(eta[troughs[8]:troughs[9]])
plt.plot(peak9,eta[peaks[9]],'xk')
plt.plot(eta[troughs[9]:troughs[10]])
plt.plot(peak10,eta[peaks[10]],'xk')
plt.plot(eta[troughs[10]:troughs[11]])
plt.plot(peak11,eta[peaks[11]],'xk')
plt.plot(eta[troughs[11]:troughs[12]])
plt.plot(peak12,eta[peaks[12]],'xk')
The peaks of these plots are at x = 54, 48, 44, 52
respectively
What I want is to get these peaks to be fixed to the same point (same x and y co-ordinate). i.e. have the black 'x's all be 'on top' of each other. Is there any way to do this without just rescaling every wave inidividually?
python
matplotlib
plot
indexing
axes
0 Answers
Your Answer