3D Gridded Plots in Python
I am looking for a library. I have 3D gridded data that I want to plot using Python. When I want to plot 2D gridded data I use matplotlib's matshow:
from matplotlib.pylab import matshow, show matshow(some_data) show()
But now I have a 3D version of this sort of raster data, and I want to be able to plot boxes (cubes) stacked in 3D space. Ideally, this would be solvable using matplotlib but my guess is the solution will be in a different library (hopefully, something in Anaconda).
As noted by @Bas Jansen, you can do this with mayavi as follows,
import mayavi.mlab as mlab import numpy as np ncubes = 12 x = np.arange(0,ncubes) y = np.arange(0,ncubes) z = np.arange(0,ncubes) value = np.arange(0,ncubes) mlab.points3d(x, y, z, value, mode='cube',scale_mode='none', scale_factor=1.0) mlab.show()
You may need to open the script with ipython --pylab=qt so the window persists. The resulting figure is,
You could do this in matplotlib, probably using patch objects to build up a cube and colour the patches as needed, however for 3D plotting, mayavi is generally easier/better.