0

I currently have a heat map which is a 2D float matrix (list of lists of floats to be accurate), and I can display it in 2D with matplotlib fairly easily, but I would like to display it in a 3D plot such that the column and row indices can by the X and Y values respectively, and the values in the matrix are Z (elevation) values. What can I use to do that? I tried using Axes3D but it didn't seem very suitable (or maybe I was using it wrong?). What I am looking to do is conceptually very simple, to pretend the matrix is a DEM and display it as such.

Also if possible I would like to be able to change viewing angles on-the-fly, without having to re-generate the plot.

Any ideas?

These two questions are related but don't quite answer my question:

3d plotting with python

Python: 3D contour from a 2D image - pylab and contourf

NB: The float matrix is rather large, typically 100x100 or more, and the last time I tried to plot it in 3D my system ran out of memory and started thrashing.

Community
  • 1
  • 1
CrystalDuck
  • 345
  • 2
  • 13
  • See: http://matplotlib.org/gallery.html#mplot3d – tacaswell Jun 19 '13 at 19:49
  • @tcaswell Those methods require all points explicitly defined in 3D space. The float matrix I have should be regularly spaced like pixels (which I already export to an image). – CrystalDuck Jun 26 '13 at 08:19
  • A 2D array of floats _does_ explicitly define points in 3D. – tacaswell Jun 26 '13 at 09:11
  • @tcaswell True, but those methods don't take it as such and require extra structures like meshgrid which requires more computations (even if just linspace) before one can display anything. (Ideally I would have needed something like this: http://matplotlib.org/examples/mplot3d/surface3d_demo.html) – CrystalDuck Jun 26 '13 at 10:01
  • That is exactly with the `mlab.surf` is doing underneath, it is just hiding it from you;) That said, `mayavi` is a much better choice for 3D work as it is opengl based. – tacaswell Jun 26 '13 at 10:07
  • @tcaswell Good point, I should have thought of that. I agree, 'mayavi' is a much "nicer" display, it has that extra "ooh, shiny" effect. – CrystalDuck Jun 26 '13 at 10:33

1 Answers1

1

Your use case seems like it is tailor made for mayavi/mlab, which has a function that does exactly what you are asking and by default permits interactive 3D rotation:

import numpy as np; from mayavi import mlab
data = np.random.random((100,100))
mlab.surf(data)
mlab.show()
aestrivex
  • 5,170
  • 2
  • 27
  • 44