具有 2 个数组和第三个包含 python 中的卡方的等高线图

Contour plot with 2 arrays and a third containing chi-squared in python

我有以下所有值的卡方:

kT=linspace(0.01,0.11,10)
v=linspace(0.05,0.5,10)

where:

KT=[]
V=[]
for i in range(len(kT)):
    for u in range(len(v)):
        KT.append(kT[i])
        V.append(v[u])

因此我有:

KT=asarray(KT)
V=asarray(V)
x=asarray(x)

其中 x[0](kT[0],v[0]) 的卡方, x[1](kT[0],v[1])

的卡方

等...

总的来说,我有 len=100 的一维数组,其中 kT[0]v[0] 给出 x[0](这是在另一个程序中完成的)。

我想将卡方绘制成等值线图,我该怎么做?我尝试使用 plt.contour 中的轮廓,但它是 x 作为二维向量。

有什么建议吗?

你可以reshape你的数组

x2d = x.reshape(10, 10)

contour 接受网格坐标向量。因此,您可以省略双循环并直接使用 kTv

pyplot.contour(v, kT, x2d)