3

I have a big set (100+) of 256x256 scalar 2D numpy arrays. Each array is basically a slice through a 3D image and each the arrays are uniformly separated.

I'm a bit of a python noob... any tips on how to create a nice 3d visualization of this data?

Do I need to compile my 100+ 2D scalar arrays into a larger 3D one?

Cheers!

Draper
  • 170
  • 3
  • 11
  • 2
    First, you need to find a library capable of doing 3D visualization ... Then you follow their API ... – mgilson Apr 17 '13 at 23:50

2 Answers2

1

You're going to need to give us a little more information, because how you visualize it depends on what you want to get out of it! Note that this question is always going to have multiple possible answers, as you're trying to display information that is inherently 3D on your 2D screen.

One way to do this is to create a movie of 2D "surface" plots, and play them back. This is basically just plotting all your slices one after another.

If you want to view all your 3D data at once, you most likely can't, as I don't know of any volumetric plotting tools for Python. Probably the closest thing is MayaVi

If you give us more information on what you want to accomplish, with as much detail as possible, we can point you to more specific examples/code resources.

staticfloat
  • 6,752
  • 4
  • 37
  • 51
  • Thanks. I picked up Mayavi but I can't seem to find any tool to plot a simple 3D scalar field! – Draper Apr 18 '13 at 00:03
  • Can you explain what you mean by "plot a simple 3d scalar field"? Can you give us an example visualization that demonstrates what you want? – staticfloat Apr 18 '13 at 00:06
0

Not entirely sure what you hope the visualization to look like? Sounds a bit like you want to visualize a 4D function?

You could create a 3D grid in space (see for example Numpy meshgrid in 3D), and then use the value of the matrix/matrix number to colour the points in a scatter plot?

Might be able to be more specific if you can elaborate on what you want to see.

Edit:

Well after your comment, it still sounds like something awfully difficult to visualize, but I guess you could do something like (I've generated random data, and have a much smaller size than you will)

import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt

(X,Y,Z) = np.mgrid[-10:10:25j, -10:10:25j, -10:10:10j]

col = np.random.rand(25,25,10)

fig = plt.figure(1)
fig.clf()
ax = Axes3D(fig)

ax.scatter(X,Y,Z, c=col)

plt.draw()

plt.show()

resulting in

enter image description here

Note, this may be a little less useless looking with non random data.

Community
  • 1
  • 1
GeorgeWilson
  • 562
  • 6
  • 17
  • For starters, a semi-transparent scatter plot would do the trick, for example. I'm using numpy.dstack to stack the arrays into a list. – Draper Apr 17 '13 at 23:57
  • Still a tad confused.. not sure this is going to be easy to see. I've added an example of what it sounds like (to me) you're trying to do.. – GeorgeWilson Apr 18 '13 at 11:25
  • This Code does not work for me. For it to run I had to call `flatten()` for the the scatter call arguments like this: `ax.scatter(X.flatten(),Y.flatten(),Z.flatten(), c=col.flatten())` – TVK Mar 23 '22 at 07:33