Python:插值矩阵图

时间:2015-10-12 19:25:06

标签: python image matrix interpolation figure

我有以下矩阵R:

R
array([[ 0.014985  ,  0.01499475,  0.01508112,  0.01588764,  0.02019902, 0.03698812,  0.12376358],
       [ 0.547997  ,  0.00300703,  0.00306113,  0.00361317,  0.23311141, 0.41010791,  0.65683355],
       [ 0.7739985 ,  0.48050374,  0.00157832,  0.32448644,  0.61655571,  0.70505395,  0.82841677],
       [ 0.9547997 ,  0.89610075,  0.75911978,  0.86489729,  0.92331114, 0.94101079,  0.96568335],
       [ 0.97739985,  0.94805037,  0.87955989,  0.93244864,  0.96165557, 0.9705054 ,  0.98284168]])

这是一个5x7矩阵,其中行对应于:

tc = [100,500,1000,5000,10000]

以下列的列:

y = [0,.00001, .0001, .001, .01, 0.1,  1]

如果我将R绘制为pcolor图片,我会得到:

z_min, z_max = -np.abs(R).max(), np.abs(R).max()
fig,ax = plt.subplots(figsize=(10,7.5))
ax.pcolor(R,cmap='RdBu',vmin=z_min, vmax=z_max)

enter image description here

我想插入矩阵以获得更详细的图像:

xnew,ynew = np.mgrid[0:1:1000j,0:1000:1000j]
tck = interpolate.bisplrep(tc,y,R,s=0, kx=1, ky=1)

我收到以下错误:

TypeError: len(x)==len(y)==len(z) must hold.

我想知道一种正确插入矩阵R给定tc = [100,500,1000,5000,10000]y = [0,.00001, .0001, .001, .01, 0.1, 1]

的方法

1 个答案:

答案 0 :(得分:1)

使用scipy.ndimage.interpolation缩放

你可以增加“缩放”直到它足够好

from scipy.ndimage.interpolation import zoom

plt.pcolor(R,cmap='RdBu')
plt.show()

R2 = zoom(R,2)
plt.pcolor(R2,cmap='RdBu')
plt.show()

R5 = zoom(R,5)
plt.pcolor(R5,cmap='RdBu')
plt.show()

R10 = zoom(R,10)
plt.pcolor(R10,cmap='RdBu')
plt.show()

您也可以使用不同的插值方法,请参阅函数的文档

1

2

4

10