【发布时间】:2012-10-07 18:10:08
【问题描述】:
我正在尝试在 matplotlib 中绘制一条线。我正在寻找正确的插值类型。我想要这样的东西
每条线都经过平滑处理。我尝试了scipy和matplotlib的几种组合,比如
x_new = np.arange(x, x_length, 1)
tck = interpolate.splrep(x, y, s=3)
y_new = interpolate.splev(x_new, tck, der=0)
ax.plot(x_new, y_new, color+lstyle)
但我得到的最好结果是
这条线代表一个递增的变量..所以它是一个错误的表示。我可以搜索什么?
谢谢
编辑:我正在考虑自己实现一个方法,但我不知道它是否已经完成..伪代码如下
take x and y
calculate spline for each three points
x[0], x[1], x[2] ... x[1], x[2], x[3] ... and so on
for each y[n] sums every computation done for it and divide by number of
computations (i.e. y[1] is computed for triplette x[0..2] and x[1..3] so the
sum is divided by two (average for each point is taken as its value)
【问题讨论】:
-
你为什么要插值?这是为了美观还是您声称知道数据点之间的值?
-
@tcaswell 我出于两个原因进行插值,主要是为了美观
标签: python numpy matplotlib scipy spline