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

Answers


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.


Need Your Help

Cannot Move a file to other folder if the same file name exist in the folder in C++

c++ visual-c++

I want to move a file from its destination to another folder, my codes work properly but if there is already a file with same name exist in the destination folder then it gives error,

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.