How to plot a data cube in python

感情迁移 提交于 2019-12-04 17:17:31

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

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!