这是你想要的吗?
import matplotlib.pyplot as plt
import numpy as np
# generate x, y
x = np.linspace(0, 10, 51)
w = np.linspace(0.5, 0.20, 10)
y = np.array([np.sin(wi*x)/wi for wi in w]) # 10 rows, 51 cols
# and a very generic z
z = np.linspace(1, 10, 10)
# note that in a surface plot the indipendent variable is Z,
# so IF our indipendent variable is y…
X, Y = np.meshgrid(x, z) ; Z = y # X, Y have 10 rows, 51 cols too
# this stuff is pretty standard, you can find info everywhere
fig = plt.figure() ; ax = fig.gca(projection='3d')
surf = ax.plot_surface(X, Y, Z, cmap='viridis')
ax.set(xlabel='x', ylabel='z', zlabel='y')
ax.view_init(elev=15, azim=-100)
fig.colorbar(surf, shrink=0.67) # the 1st arg is the output of plot_surface
颜色图是默认的,您可以按名称选择不同的。您可以使用 . 查看完整的颜色图名称列表plt.colormaps()
。