python中的等高线图

python中的等高线图,python,numpy,matplotlib,contour,Python,Numpy,Matplotlib,Contour,我有三个大量的数据。这些是x和y值以及每个xy点的温度值。我想绘制每个点,并插值点之间的面积,以获得一个连续的曲面。我遇到的问题是指定温度值。我无法让它使用相同数量的x、y和z(温度)值,我可以在网上找到的所有示例都使用x和y函数来创建z,或者为xy网格上的每个点创建z值。 有没有一个简单的方法可以做到这一点 import numpy as np import matplotlib.pyplot as plt fig, axs = plt.subplots() x = np.linspace

我有三个大量的数据。这些是x和y值以及每个xy点的温度值。我想绘制每个点,并插值点之间的面积,以获得一个连续的曲面。我遇到的问题是指定温度值。我无法让它使用相同数量的x、y和z(温度)值,我可以在网上找到的所有示例都使用x和y函数来创建z,或者为xy网格上的每个点创建z值。 有没有一个简单的方法可以做到这一点

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots()

x = np.linspace(0, 1, 100)
y = np.linspace(0,1,100)
X, Y = np.meshgrid(x, y)
#Z = np.sin(X)*np.sin(Y)  # want to specify not an equation
Z = np.linspace(1,2,100)
levels = np.linspace(-1, 1, 40)
cs = axs.contourf(X, Y, Z, levels=levels)
fig.colorbar(cs, ax=axs, format="%.2f")
plt.show()
更新:

这是我到目前为止所拥有的。我仍然需要找出一个好的方法来填充点之间的区域。有人有什么想法吗

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots()

# create a grid in the correct shape / size
x = np.linspace(0, 1, 3)
y = np.linspace(0,1,3)
X, Y = np.meshgrid(x, y)

# specify and change the relevent areas
y = [1,2,0]  # location of point in x direction
x =[2,1,1]  #location of point in y direction
z = [40,30,20]  #temperature
Z = np.arange(1,10).reshape((3,3))
Z[y,x] = z

levels = np.linspace(0, 40, 40)
cs = axs.contourf(X, Y, Z, levels=levels)
fig.colorbar(cs, ax=axs, format="%.2f")
plt.show()

人们之所以使用x和y的函数,是因为Z值必须是x和y的函数。在测试代码中,Z是1D,但它需要是2D才能绘制轮廓

如果Z(温度)值的形状与x和y坐标相同,则该值应该有效

x = np.linspace(0, 1, 100)
y = np.linspace(0,1,100)

X, Y = np.meshgrid(x, y)
#Z = np.sin(X)*np.sin(Y)  # want to specify not an equation
Z = np.linspace(1,2,100)

print X.shape

print Z.shape
(100L,100L)

(100升)


人们之所以使用x和y的函数,是因为Z值必须是x和y的函数。在测试代码中,Z是1D,但它需要是2D才能绘制轮廓

如果Z(温度)值的形状与x和y坐标相同,则该值应该有效

x = np.linspace(0, 1, 100)
y = np.linspace(0,1,100)

X, Y = np.meshgrid(x, y)
#Z = np.sin(X)*np.sin(Y)  # want to specify not an equation
Z = np.linspace(1,2,100)

print X.shape

print Z.shape
(100L,100L)

(100升)


设置网格网格后,只需写入
Z=np.zeros(X.shape)
,此行将创建一个形状为X数组的empry Z数组。设置网格网格后,此问题有答案,只需写入
Z=np.zeros(X.shape)
,此行将创建一个形状为X数组的empry Z数组。此问题有答案