简体   繁体   中英

matplotlib: 3D wireframe plot from 2D plots

I have some data and I write a code for plot it as scatter point:

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()

How can I make a wireframe plot from this? (I want to connect these points by a grid).

Thanks

Simply use numpy.meshgrid to generate the x- and y-grids and the stack the z-values together using numpy.vstack .

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM