在python上反转三维网格

2024-10-03 09:20:06 发布

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

我有下面的代码

x = np.array([140, 200, 260, 320, 380, 440, 500])
y = np.array([40, 60, 80, 100, 120, 140, 160])
X, Y = np.meshgrid(x,y)

Z =  np.array([[1.4496, 1.3912, 1.3607, 1.3399, 1.326, 1.315, 1.3070,[1.3929, 1.3357, 1.3055, 1.2845, 1.2700, 1.2600, 1.2528],[1.3556, 1.2999, 1.2687, 1.2497, 1.2370, 1.2250, 1.2165],[1.3270, 1.2750, 1.2450, 1.2240, 1.2100, 1.20076, 1.19299],[1.3078, 1.25377, 1.2233, 1.2050, 1.1900, 1.1805, 1.17377],[1.2897, 1.2394, 1.208, 1.188, 1.176, 1.165, 1.15791],[1.2767, 1.2256, 1.1952, 1.17492, 1.16159, 1.15237, 1.1446]])

x2 = np.arange(min(x), max(x), 1)
y2 = np.arange(min(y), max(y), 11)

f = interp2d(x, y, Z, kind='quintic')

PLot is here

如何将其反转,使z轴(色条)上的值变为x轴或y轴?你知道吗


Tags: 代码npminarraymaxx2kindy2
1条回答
网友
1楼 · 发布于 2024-10-03 09:20:06

那怎么办

import matplotlib.pyplot as plt
from matplotlib.tri import Triangulation
import numpy
Z = numpy.array([[1.4496, 1.3912, 1.3607, 1.3399, 1.326, 1.315, 1.3070],
                 [1.3929, 1.3357, 1.3055, 1.2845, 1.2700, 1.2600, 1.2528],
                 [1.3556, 1.2999, 1.2687, 1.2497, 1.2370, 1.2250, 1.2165],
                 [1.3270, 1.2750, 1.2450, 1.2240, 1.2100, 1.20076, 1.19299],
                 [1.3078, 1.25377, 1.2233, 1.2050, 1.1900, 1.1805, 1.17377],
                 [1.2897, 1.2394, 1.208, 1.188, 1.176, 1.165, 1.15791],
                 [1.2767, 1.2256, 1.1952, 1.17492, 1.16159, 1.15237, 1.1446]])
x = numpy.array([140, 200, 260, 320, 380, 440, 500])
y = numpy.array([40, 60, 80, 100, 120, 140, 160])
Z = Z.flatten()
X = numpy.repeat(x, y.shape[0])
Y = numpy.tile(y, x.shape[0])
fig, ax = plt.subplots()
triMesh = Triangulation(X, Z)
tctrf = ax.tricontourf(triMesh, Y, 31)
fig.colorbar(tctrf)
plt.show()

产生 enter image description here

相关问题 更多 >