2015-11-26 90 views
-2

我试图使我的图形平滑与scipy,但结果是一条水平线。Scipy使图形更平滑

代码:

import numpy as np 
import matplotlib.pyplot as plt 
from scipy.interpolate import spline 

dd = [1.0, 0.7071067811865476, 0.5, 0.3535533905932738, 0.25, 0.1767766952966369] 
y = range(0,6) 

dd1 = np.array(dd) 
y1 = np.array(y) 

xsmooth = np.linspace (dd1.max(),dd1.min(),5) 
ysmooth = spline (dd1,y1,xsmooth) 

plt.plot(xsmooth ,ysmooth) 
plt.show() 

在此先感谢

+0

你的代码不能运行:'ValueError异常:形状(8,6)和(5,)未对齐:6(dim 1)!= 5(dim 0)'。 – EelkeSpaak

+0

@SiHa yes.thanks SiHa。 –

回答

0

我想你可能x和y在你的代码混合起来。 如果DD是你的y值和ÿ是你的x值,你可以像这样执行样条插补:

import numpy as np 
import matplotlib.pyplot as plt 
from scipy.interpolate import spline 

y = [1.0, 0.7071067811865476, 0.5, 0.3535533905932738, 0.25, 0.1767766952966369] 
x = range(0,6) 

y = np.array(y) 
x = np.array(x) 

xsmooth = np.linspace (x.min(),x.max(),20) # an x vector with more intermediate values 
ysmooth = spline(x,y,xsmooth) 

plt.plot(xsmooth ,ysmooth) 
plt.plot(x,y,'o') 
plt.show()