从三个数据列在python上创建等高线图

2024-05-29 06:46:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两列输入数据,作为我的x轴和y轴,还有第三列与输入相关的结果数据。我有36个输入组合,然后是36个结果

我想达到这样的效果

enter image description here

我尝试过使用cmap,但被告知z数据是1D的,需要是2D的,我不明白如何解决这个问题 下面还附上了另一种方法

data = excel[['test','A_h','f_h','fore C_T','hind C_T','fore eff','hind eff','hind C_T ratio','hind eff ratio']]
    
x = data['A_h']
y = data['f_h']
z = data['hind C_T ratio']
X,Y = np.meshgrid(x,y)
Z = z
    
plt.pcolor(x,y,z)

Tags: 数据方法testdatanppltexcelcmap
1条回答
网友
1楼 · 发布于 2024-05-29 06:46:56

如果您有数组[1, 2, 3][4, 5, 6],那么meshgrid将为您提供两个3x3的数组:[[1, 1, 1], [2, 2, 2], [3, 3, 3]][[4, 5, 6], [4, 5, 6], [4, 5, 6]]。在你的例子中,你似乎已经考虑到了这一点,因为你有36个x,y,z,值。所以meshgrid就没有必要了

如果您的阵列定义良好(已采用上述11122233和45645656格式),则您可以对其进行重塑:

x = np.reshape(data['A_h'], (6,6))
y = np.reshape(data['f_h'], (6,6))
z = np.reshape(data['hind C_T ratio'], (6,6))
plt.contourf(x, y, z)

有关详细信息,您可以查看有关contourf的更多帮助

另一方面,如果您的数据是不规则的(36个点不构成网格),那么您将不得不使用上面@obchardon建议的griddata

相关问题 更多 >

    热门问题