questionhang
questionhang

Reputation: 763

3dplot scatter points via python

I just used numpy.loadtxt('filename', usecols=(0,)) to load a csv with the following format:

x,y,z
1.1,2.2,3.3
5.5,1.45,6.77

(There are ~1M lines). I'd like to make a scatterplot. I searched the web and found numpy.meshgrid and mlab.surf but I'm not sure what to do. Please point me in the right direction.

Upvotes: 0

Views: 94

Answers (2)

Steve Barnes
Steve Barnes

Reputation: 28415

There is a very simple example from here.

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

You just need to parse your data instead of using randrange.

Upvotes: 1

BitHigher
BitHigher

Reputation: 501

I think you can use matplotlib, it's very powerful, and widely used, most importantly, it has good document and is easy to use.

Hope helps!

Upvotes: 1

Related Questions