我有一个非常奇怪的bisplrep行为。
在以下示例中重现了该问题。 首先是创建样本数据 然后在精细网格上选择分散数据,并尝试应用具有不同结节数(tx,ty)的bisplrep。 那时,我已经有了问题。有些图表根本没有表示数据。
from scipy.interpolate import bisplrep,bisplev
from numpy import arange
import numpy as np
from matplotlib import pyplot as mpl
#create data
x,y = np.mgrid[slice(0, 100, 0.1),
slice(0,50,0.1)]
z = cos(x/10)*sin(y/5)**2
# random selection of scattered data
select = np.random.randint(2, size=x.shape)
for i in range(8):
select *= np.random.randint(2, size=x.shape)
sx = x.flatten().compress(select.flatten() == 1)
sy = y.flatten().compress(select.flatten() == 1)
sz = z.flatten().compress(select.flatten() == 1)
print len(sx)
#plot original data
fig,axs = subplots(nrows = 4,ncols = 3)
axs[0,0].pcolormesh(x,y,z)
axs[0,0].scatter(sx,sy,alpha=0.5)
axs[0,0].set_xlim(0,100)
axs[0,0].set_ylim(0,50)
#try to uncomment/comment this line
#axs[0,0].set_title('original data')
def get_rz(dx,dy,ax):
print dx,dy
#ix,iy are the knots for bisplrep
ix = arange(0, 100, dx)
iy = arange(0,50,dy)
#ox,oy are the interpolation points (same as origianl grid)
ox = arange(0, 100, 0.1)
oy = arange(0,50,0.1)
#interpolation with bisplrep
tck = bisplrep(sx,sy,sz,task = -1, nxest = len(ix) , nyest = len(iy),tx = ix,ty = iy,s=0)
rz = bisplev(ox,oy,tck)
c = ax.contourf(x,y,rz,vmin=-1,vmax = 1)
# scatx and scat y are just for plot
scatx,scaty = np.mgrid[slice(0, 100, dx),
slice(0,50,dy)]
ax.plot(scatx.flatten(),scaty.flatten(),'+',alpha = 0.5)
ax.set_title('dx=%s dy=%s'%(dx,dy))
return rz
get_rz(dx=1,dy=1,ax=axs[1,0])
get_rz(dx=1,dy=2,ax=axs[1,1])
get_rz(dx=1,dy=3,ax=axs[1,2])
get_rz(dx=2,dy=1,ax=axs[2,0])
get_rz(dx=2,dy=2,ax=axs[2,1])
get_rz(dx=2,dy=3,ax=axs[2,2])
get_rz(dx=3,dy=1,ax=axs[3,0])
get_rz(dx=3,dy=2,ax=axs[3,1])
get_rz(dx=3,dy=3,ax=axs[3,2])
#try to uncomment/comment this line
fig.tight_layout(pad = 0.1,h_pad=0.1,w_pad=0.1)
fig.show()
现在,我尝试评论/取消评论一两行,结果不同...... 它看起来像是一个记忆问题。
你能重现这个问题吗? 有什么想法来解决这个问题吗?
谢谢
这里有我得到的两个例子(似乎我不允许发布图片)... http://i.stack.imgur.com/gZZc4.png http://i.stack.imgur.com/0344u.png
编辑: 我尝试使用LSQBivariateSpline具有相同的结果 和fitpack的f2py vertion:dfitpack.surfit_lsq它也是一样的