我下面有这个代码
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')
如何反转此值,以使z轴(颜色栏)上的值变为x轴或y轴?
答案 0 :(得分:1)
那
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()