如何使用mayavi,請(qǐng)參見(jiàn)上一篇文章。
1.使用mayavi
代碼
- import enthought.mayavi.mlab as mylab
- import numpy as np
- x, y, z, value = np.random.random((4, 40))
- mylab.points3d(x, y, z, value)
- mylab.show()
效果
2.使用mpl_toolkits
代碼
- import pylab as p
- import mpl_toolkits.mplot3d.axes3d as p3
- import numpy as np
- #data is an ndarray with the necessary data and colors is an ndarray with #'b', 'g' and 'r' to paint each point according to its class ...
- fig=p.figure()
- point_num=100
- data=np.random.random((point_num,3))
- colors=[['b','g','r'][int(i*2.999)] for i in np.random.random((point_num,1))]
- ax = p3.Axes3D(fig)
- ax.scatter(data[:,0], data[:,1], data[:,2], c=colors)
- ax.set_xlabel('X')
- ax.set_ylabel('Y')
- ax.set_zlabel('Z')
- fig.add_axes(ax)
- p.show()
效果
3.帶標(biāo)簽的
代碼
- import numpy as np
- from mpl_toolkits.mplot3d import Axes3D
- import matplotlib.pyplot as plt
-
- def randrange(n, vmin, vmax):
- return (vmax-vmin)*np.random.rand(n) + vmin
-
- fig = plt.figure()
- ax = fig.add_subplot(111, projection='3d')
- n = 100
-
- for c, m, zl, zh in [('r', 'o', -50, -25), ('b', '^', -30, -5)]:
- xs = randrange(n, 23, 32)
- ys = randrange(n, 0, 100)
- zs = randrange(n, zl, zh)
- ax.scatter(xs, ys, zs, c=c, marker=m)
-
- ax.set_xlabel('X Label')
- ax.set_ylabel('Y Label')
- ax.set_zlabel('Z Label')
- plt.show()
效果
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)
點(diǎn)擊舉報(bào)。