将平均移动平均曲线安装到曲线的问题
我在Python中的移动平均功能有问题。我尝试使用几种方法,但它们没有起作用。我在光线曲线上使用良好工作之前使用的移动平均值,但分阶段发生问题: 具有拟合移动平均值的相图
我不知道为什么它不正常。这是我使用的代码:
import matplotlib.pyplot as plt
import numpy as np
data = np.genfromtxt('phase.txt', dtype='float,float', names=["Time","Flux"])
t = data["Time"]
flux = data["Flux"]
def movingaverage(interval, window_size):
window = np.ones(int(window_size))/float(window_size)
return np.convolve(interval, window,'same')
av = movingaverage(flux, 10)
plt.plot(t,flux,"C0.", ms=2)
plt.plot(t,av,"r")
plt.show
我希望这样的东西: 拟合的移动平均线
这是我的文件,其中有两个列中的值: bpky4/查看?usp =共享
I have a problem with the Moving average function in Python. I tried using a couple of methods but they didn't work. Moving average that I used before work well on my light curve, but problem occurs with phased diagram:
Phase diagram with fitted moving average
I don't know why it's not working properly. Here is a code I use:
import matplotlib.pyplot as plt
import numpy as np
data = np.genfromtxt('phase.txt', dtype='float,float', names=["Time","Flux"])
t = data["Time"]
flux = data["Flux"]
def movingaverage(interval, window_size):
window = np.ones(int(window_size))/float(window_size)
return np.convolve(interval, window,'same')
av = movingaverage(flux, 10)
plt.plot(t,flux,"C0.", ms=2)
plt.plot(t,av,"r")
plt.show
I would expect something like this:
fitted moving average
Here is my file with values in two columns:
https://drive.google.com/file/d/1IQScAo8iduv90wuaor8o9eJT85qBpKY4/view?usp=sharing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我注意到您的时间值和相应的通量值未正确排序。时间值应该上升。
这会产生您期望的结果吗?
我曾尝试过同时对时间值进行排序以及分类时间和磁通值。
仅分类时间值:

排序时间值和磁通值:

您看起来更合理?
I noticed that your time values and the corresponding flux values are not properly sorted. Time values should be ascending.
Does this yield the result you were expecting?
I have tried both, only sorting time values as well as sorting time and flux values.
Only sorting time values:

Sorting time values and flux values:

Which one looks more plausible to you?
您的数据非常分散。考虑在较大的窗口上平均。
Your data is quite scattered. Consider averaging over a larger window.