【发布时间】:2017-02-25 14:42:30
【问题描述】:
我一直在尝试根据这些值创建一条平滑线,但我的结果中不能有负值。到目前为止,我尝试的所有方法都给出了负值。希望得到一些帮助。
import matplotlib.pyplot as plt
from scipy.interpolate import UnivariateSpline
import numpy as np
y = np.asarray([0,5,80,10,1,10,40,30,80,5,0])
x = np.arange(len(y))
plt.plot(x, y, 'r', ms=5)
spl = UnivariateSpline(x, y)
xs = np.linspace(0,len(y)-1, 1000)
spl.set_smoothing_factor(2)
plt.plot(xs, spl(xs), 'g', lw=3)
plt.show()
【问题讨论】:
标签: python numpy matplotlib scipy interpolation