我想创建一个 3D 曲面图,而每次迭代的数组长度不同,因此轴的长度不同。为了更好地理解,我在这里有一个工作示例。你注意到
J
依赖于 M
所以每次迭代中数组的长度是不同的。当我绘制它时,它不会生成曲面图,而只会生成一个在 J
轴上延伸的二维图。任何帮助将不胜感激。
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')
ax.set_xlabel("M")
ax.set_ylabel("J")
ax.set_zlabel("K")
for M in range(1, 5):
liss = []
for J in range(M, M*3):
K = M + J
liss.append(K)
L = np.array([liss])
J = np.array([i for i in range(M, M*3)])
M, J = np.meshgrid(M, J)
surf = ax.plot_surface(M, J, L, cmap=cm.coolwarm,
linewidth=0.1, alpha=0.7)
fig.colorbar(surf, shrink=0.5, aspect=5, pad=0.1);