开发者

How to plot a data cube in python

I was wondering if there's a way to plot a data cube in Python. I mean I have three coordinate for every point

x=part.points[:,0]
y=part.points[:,1]
z=part.points[:,2]

And for every point I have a scalar field t(x,y,z)

I would like to plot a 3D data cube showing the position of the point and for every point开发者_开发知识库 a color which is proportional to the scalar field t in that point.

I tried with histogramdd but it didn't work.


You can use matplotlib. Here you have a working example (that moves!):

import random
from matplotlib import pyplot
from mpl_toolkits.mplot3d import Axes3D

mypoints = []
for _ in range(100):
    mypoints.append([random.random(),    #x
                    random.random(),     #y
                    random.random(),     #z
                    random.randint(10,100)]) #scalar

data = zip(*mypoints)           # use list(zip(*mypoints)) with py3k  

fig = pyplot.figure()
ax = fig.add_subplot(111, projection='3d')

ax.scatter(data[0], data[1], data[2], c=data[3])
pyplot.show()

How to plot a data cube in python

You probably have to customize the relation of your scalar values with the corresponding colors.
Matplotlib has a very nice look but it can be slow drawing and moving these 3D drawings when you have many points. In these cases I used to use Gnuplot controlled by gnuplot.py. Gnuplot can also be used directly as a subprocess as shown here and here.


Another option is Dots plot, produced by MathGL. It is GPL plotting library. Add it don't need many memory if you save in bitmap format (PNG, JPEG, GIF and so on).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜