您如何平滑数组中的值(没有多项式方程式)?

所以基本上我有一些数据,我需要找到一种方法来平滑它(以便由此产生的线条平滑而不抖动)。绘制出数据后,现在看起来像这样:

您如何平滑数组中的值(没有多项式方程式)?

我希望它看起来像这样:

您如何平滑数组中的值(没有多项式方程式)?

我尝试使用this numpy方法来获得直线方程,但是由于图形重复(它有多个读数,所以图形上升,饱和,然后下降然后重复该倍数)对我不起作用次),因此实际上并没有一个方程可以表示这一点。

我也尝试了this,但是由于上述原因,它无法正常工作。

图形的定义如下:

gx = [] #x is already taken so gx -> graphx
gy = [] #same as above

#Put in data

#Get nice data #[this is what I need help with]

#Plot nice data and original data

plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.show()

我认为最适用于我的解决方案的方法是获取每2个点的平均值并将其设置为两个点的值,但是这种想法对我而言并不正确-可能会失去潜在的价值。 / p>

yingcaiiacgniy 回答:您如何平滑数组中的值(没有多项式方程式)?

您可以使用无限远景滤镜

import numpy as np
import matplotlib.pyplot as plt

x = 0.85 # adjust x to use more or less of the previous value
k = np.sin(np.linspace(0.5,1.5,100))+np.random.normal(0,0.05,100)
filtered = np.zeros_like(k)
#filtered = newvalue*x+oldvalue*(1-x)
filtered[0]=k[0]
for i in range(1,len(k)):
# uses x% of the previous filtered value and 1-x % of the new value
    filtered[i] = filtered[i-1]*x+k[i]*(1-x) 

plt.plot(k)
plt.plot(filtered)
plt.show()
,

我想出了一个问题,通过平均4个结果,我可以显着平滑图表。这是一个演示:

demo

希望这可以帮助需要它的人

本文链接:https://www.f2er.com/3145085.html

大家都在问