Python 使用二维数组数据绘制等高线并找到中心

Python plot contour lines using a 2d array data and find the center

我在看一篇名为'Geolocation assessment for CrIS sensor data records'的论文,有这样一个图

The cost function is defined as the RMSE varying with the number of shifted pixels in the along- and cross-track directions.表示[-5,-5]是像素从[0,0]向左移动5步,向下移动5步,[-5,-5]的值是两个数据集之间的rmse,已经计算出来了。

我也有类似的问题,但是不知道怎么画这样的图,有人知道吗?

编辑:

现在我知道使用pyplot.imshow(rmsedataset,...)可以画成这样,它们看起来像椭圆,我怎样才能找到最小椭圆的中心(+在哪里)?

根据论文。 Since each contour line can be treated as a closed ellipse, a fitting ellipse can be found, and the center of the ellipse reflects the minimum of the cost function.

这是一个使用 numpymatplotlib

的示例

首先我们创建 1500 到 5500 之间的随机数并创建一个 50 x 100 的 numpy 数组,然后我们简单地绘制给出颜色条的数据。

希望这对您有所帮助。

演示代码:

import numpy as np
from numpy import array
import matplotlib.pyplot as plt
import random


#Generate a list of 5000 int between 1200,5500
M = 5000
myList = [random.randrange(1200,5500)  for i in xrange(0,M)]

#Convert to 50 x 100 list
n = 50
newList = [myList[i:i+n] for i in range(0, len(myList), n)]

#Convert to 50 x 100 numpy array
nArray = array(newList)
print nArray

a11=nArray.reshape(50,100)
fig = plt.figure()
fig.suptitle('Test Title')
plt.xlabel('X-Axis')
plt.ylabel('Y-Axis')
plt.imshow(a11, cmap='hot')
plt.colorbar()
plt.show()

情节