我有一些数据,我编写了一个代码,用于将其绘制为散点图:
import matplotlib as mpl
from mpl_toolkits.mplot3d.axes3d import Axes3D
import numpy as np
x = np.linspace(-20, 0, 50)
z1 = np.random.randn(50)
z2 = np.random.randn(50)
z3 = np.random.randn(50)
z4 = np.random.randn(50)
z5 = np.random.randn(50)
z6 = np.random.randn(50)
fig = plt.figure()
ax = Axes3D(fig)
ax.scatter3D(xs=x, zs=z1, ys=[0.6]*50, zdir='z', alpha=1)
ax.scatter3D(xs=x, zs=z2, ys=[0.8]*50, zdir='z', alpha=1)
ax.scatter3D(xs=x, zs=z3, ys=[1.02]*50, zdir='z', alpha=1)
ax.scatter3D(xs=x, zs=z4, ys=[1.2]*50, zdir='z', alpha=1)
ax.scatter3D(xs=x, zs=z5, ys=[1.4]*50, zdir='z', alpha=1)
ax.scatter3D(xs=x, zs=z6, ys=[1.6]*50, zdir='z', alpha=1)
plt.show()
如何从中制作线框图? (我想通过网格连接这些点。)
由于
答案 0 :(得分:1)
只需使用numpy.meshgrid
生成x和y网格,并使用numpy.vstack
将z值叠加在一起。
X,Y = np.meshgrid(x,np.asarray([0.6,0.8,1.02,1.2,1.4,1.6]))
Z = np.vstack((z1,z2,z3,z4,z5,z6))
ax.plot_wireframe(X,Y,Z)