enthought / mayavi

3D visualization of scientific data in Python
http://docs.enthought.com/mayavi/mayavi/
Other
1.32k stars 285 forks source link

Project matrix onto plane in 3D #227

Open nicolasbock opened 9 years ago

nicolasbock commented 9 years ago

Hi,

I would like to project a matrix onto a plane in a 3D plot such that the matrix elements are colored by their magnitude (ideally using some sort of heat map colormap). I have several matrices and each would be projected onto a different plane, e.g. A -> xy-plane, B -> xz-plane, C -> yz-plane. I have experimented with mlab.points3d(mode='2dsquare') but can't figure out how to change the normal on the glyphs such that they are all in the desired plane. I am also running into issues with coloring, at this point only the outline of the glyphs is colored, and not the inside of them.

Thanks already,

nick

dmsurti commented 9 years ago

Can you share a simplified code sample that demo's the issues you are facing for your given problem?

nicolasbock commented 9 years ago
#!/usr/bin/env python2

import mayavi.mlab as mlab
import numpy

@mlab.show
def main():
    import itertools
    A = numpy.matrix(numpy.random.rand(8, 8))
    B = numpy.matrix(numpy.random.rand(8, 8))
    C = numpy.matrix(numpy.random.rand(8, 8))
    for (i, j) in itertools.product(range(A.shape[0]), range(A.shape[1])):
        mlab.points3d([i], [0], [j], mode='2dsquare', scale_factor=1, opacity=1, colormap="gist_heat", color=(abs(A[i, j]), 0, 0))
        mlab.points3d([0], [j], [i], mode='2dsquare', scale_factor=1, opacity=1, colormap="gist_heat", color=(abs(B[i, j]), 0, 0))
        mlab.points3d([i], [j], [0], mode='2dsquare', scale_factor=1, opacity=1, colormap="gist_heat", color=(abs(C[i, j]), 0, 0))

if __name__ == "__main__":
    main()