开发者

Plotting 3D scatter with python?

Plotting 3D scatter with python?

Is there any module that could aid me开发者_StackOverflow in producing something like this?


Like this, say?

Plotting 3D scatter with python?


(source: sourceforge.net)

The matplotlib examples gallery is a wonderful thing to behold.


Code copied from the linked example.

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


Adapted from the Cookbook

from numpy import *
import pylab as p
import mpl_toolkits.mplot3d.axes3d as p3

x=random.randn(100)
y=random.randn(100)
z=random.randn(100)

fig=p.figure()
ax = p3.Axes3D(fig)
ax.scatter3D(ravel(x),ravel(y),ravel(z))
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
p.show()


I think matplotlib should be able to do something like that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜