我正在尝试绘制3D图表,其中我的Z值将分配给每个[X,Y]有序对。例如,这些是我的X,Y和Z值:
X = [1,2,3,4,5]
Y = [1,2,3,4,5]
Z = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50,]
和Z值,对应于以下[X,Y]有序对:
Z = [X[0]Y[0], X[0]Y[1], X[0]Y[2],...., X[5]Y[4], X[5]Y[5]]
谢谢!
您可以使用np.meshgrid执行此操作
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
X = [1,2,3,4,5]
Y = [1,2,3,4,5]
Z = [10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50, 10, 20, 30, 40, 50,]
xy = np.array(np.meshgrid(X,Y)).reshape(-1,2)
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot(xy[:,0],xy[:,1],Z)
plt.show()
您也可以使用散点图
ax.scatter(xy[:,0],xy[:,1],Z)