python中的插值结果向右旋转90度

Interpolation result in python is rotated 90 degrees to the right

我在 python 和 this tutorial 之后使用 rbf 构造了一个插值代码。更准确地说,代码显示在 04:57.

import numpy as np
import matplotlib.pyplot as plt
from scipy import interpolate
import pylab as py
import scipy

token = open('Ydata_48_of_50.txt','r')
linestoken=token.readlines()
tokens_column_numberX = 0
tokens_column_numberY = 1
tokens_column_numberF = 2

resulttokenX=[]
resulttokenY=[]
resulttokenF=[]
for x in linestoken:
    resulttokenX.append(x.split()[tokens_column_numberX])
    resulttokenY.append(x.split()[tokens_column_numberY])
    resulttokenF.append(x.split()[tokens_column_numberF])
token.close()

resulttokenX2 = np.array(resulttokenX)
resulttokenY2 = np.array(resulttokenY)
resulttokenF2 = np.array(resulttokenF)    
newfunc=interpolate.Rbf(resulttokenX2.astype('float'), resulttokenY2.astype('float'), resulttokenF2.astype('float'), function='multiquadric')
    xnew, ynew=np.mgrid[340:350:100j, 23:32:100j]
    fnew=newfunc(xnew, ynew)
    
    #create image plot
    py.figure(1)
    py.clf()
    py.imshow(fnew, extent=[340, 350, 23, 32], cmap=py.cm.jet)

上面的代码是我的程序示例。结果可以在这张图片中看到

不幸的是,我做错了什么。生成的插值看起来应该像上一张图​​像的 90 度转弯。

我试图改变 np.np.mgrid 的值,但我还没有找到 returns 我想要的任何组合。请注意,我正在处理纬度和经度。我的原始数据中有 19 个纬度值和 21 个经度值。

知道会发生什么吗?

最后,我设法通过结合使用翻转列表和更改轴来“解决”这个问题。这是代码:

import numpy as np
import matplotlib.pyplot as plt
from scipy import interpolate
import pylab as py
import scipy

token = open('Ydata_48_of_50.txt','r')
linestoken=token.readlines()
tokens_column_numberX = 0
tokens_column_numberY = 1
tokens_column_numberF = 2

resulttokenX=[]
resulttokenY=[]
resulttokenF=[]
for x in linestoken:
    resulttokenX.append(x.split()[tokens_column_numberX])
    resulttokenY.append(x.split()[tokens_column_numberY])
    resulttokenF.append(x.split()[tokens_column_numberF])
token.close()


resulttokenXflip=resulttokenX[::-1]
resulttokenYflip=resulttokenY[::-1]
resulttokenFflip=resulttokenF[::-1]

resulttokenX2 = np.array(resulttokenX)
resulttokenX2flip = np.array(resulttokenXflip)

resulttokenY2 = np.array(resulttokenY)
resulttokenY2flip = np.array(resulttokenYflip)

resulttokenF2 = np.array(resulttokenF)
resulttokenF2flip = np.array(resulttokenFflip)

#El error tiene que venir del hecho de que Y2 está definida de menor a mayor

len(resulttokenX2)

newfunc=scipy.interpolate.Rbf(resulttokenY2flip.astype('float'), resulttokenX2.astype('float'), resulttokenF2.astype('float'), function='linear')
xnew, ynew=np.mgrid[ 23:32:90j, 340:350:100j]
fnew=newfunc(xnew, ynew)

#create image plot
py.figure(1)
py.clf()
py.imshow(fnew, extent=[ 340, 350, 23,32], cmap=py.cm.jet)