我正在尝试在python中绘制两个不同频率的正弦波的总和-我已经在excel中做到了,现在想在python中复制它。
谢谢。
import numpy as np
import matplotlib.pyplot as plot
orbitperiod = .36
lumorbitperiod = 3.25
synodicperiod = 1/abs((1/orbitperiod)-(1/lumorbitperiod))
highesthigh = 3112
lowesthigh = 2709
highestlow = 2023
lowestlow = 1665
halfofhighrange = abs(highesthigh-highestlow)/2
halfoflowrange = abs(highestlow-lowestlow)/2
lowmean = (highestlow+lowestlow)/2
time = np.arange(0, 5, 0.01);
#plot first sine wave
plot.plot(time*365*orbitperiod, \
(np.sin(time*np.pi*2)*halfoflowrange+lowmean))
#plot second sine wave
plot.plot(time*365*synodicperiod, \
(np.sin(time*np.pi*2)*halfofhighrange+halfofhighrange))
我想要一个正弦波之和的图,而不是两个单独的正弦波。
答案 0 :(得分:0)
您可以使两个正弦函数的time
坐标保持相同,但是可以水平sine(2*Pi*time / period)
拉伸正弦波:
import numpy as np
import matplotlib.pyplot as plot
orbitperiod = .36
lumorbitperiod = 3.25
synodicperiod = 1/abs((1/orbitperiod)-(1/lumorbitperiod))
highesthigh = 3112
lowesthigh = 2709
highestlow = 2023
lowestlow = 1665
halfofhighrange = abs(highesthigh-highestlow)/2
halfoflowrange = abs(highestlow-lowestlow)/2
lowmean = (highestlow+lowestlow)/2
time = np.arange(0, 2, 0.01) ;
sine_one = np.sin(time*np.pi*2 / orbitperiod)*halfoflowrange+lowmean
plot.plot(time * 365, sine_one, label='first Sine')
sine_two = np.sin(time*np.pi*2 / synodicperiod)*halfofhighrange+halfofhighrange
plot.plot(time * 365, sine_two, label='Second Sine')
sine_sum = sine_one + sine_two
plot.plot(time * 365 , sine_sum, label='Summed Sines')
plot.legend(); plot.show()