我有一个 3D 数组,想使用plt.pcolormesh
它制作 2D 绘图,但我不断收到错误消息
ValueError: 需要 1 个以上的值才能解包。
我x
和y
阵列都是长度为59和所述z
阵列是长度为59 * 59 = 3481,因为x
与y
现在是一个矩阵。
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
points = [(54.5, 17.041667, 31.993), (54.5, 17.083333, 31.911), (54.458333, 17.041667, 31.945), (54.458333, 17.083333, 31.866)]
points = sorted(points) # order points by x, then by y
(x1, y1, q11), (_x1, y2, q12), (x2, _y1, q21), (_x2, _y2, q22) = points
interp2d=[]
nums = np.linspace(x1, x2, num = 60, endpoint=True)
numms = np.linspace(y1, y2, num = 60, endpoint=True)
X, Y = np.meshgrid(nums[:-1], numms[:-1], indexing='xy')
for i in range(len(nums)-1):
for j in range(len(numms)-1):
x=nums[i]
y=numms[j]
interp = (q11 * (x2 - x) * (y2 - y) +
q21 * (x - x1) * (y2 - y) +
q12 * (x2 - x) * (y - y1) +
q22 * (x - x1) * (y - y1)
) / ((x2 - x1) * (y2 - y1) + 0.0)
interp2d.append(interp)
interp2d = np.asarray(interp2d)
fig, (ax1, ax2) = plt.subplots(1,2, sharex=True)
ax2.pcolormesh(X,Y,interp2d, cmap=plt.cm.BuPu_r)
cbar = plt.colorbar()
plt.show()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句