user10050371
user10050371

Reputation: 71

plot 3d numpy array as a 3d image using matplotlib or PIL

After looking at various related answers, I could not figure out a straight way.

I have a 3-d numpy array of shape (390, 280, 160). I want to visualize this as an image. What could be the simplest way to do it?

Upvotes: 4

Views: 3413

Answers (1)

taras
taras

Reputation: 6915

Here is a minimal example of volumetric plot using mayavi.
You can find more examples of 3d data visualization here

from mayavi import mlab
import numpy as np

s = np.random.rand(20, 20, 20)
volume = mlab.pipeline.volume(mlab.pipeline.scalar_field(s), vmin=0, vmax=0.8)

mlab.draw()
mlab.savefig('output.png')

enter image description here

From mayavi docs

For such a visualization, tweaking the opacity transfer function is critical to achieve a good effect. Typically, it can be useful to limit the lower and upper values to the 20 and 80 percentiles of the data, in order to have a reasonable fraction of the volume transparent.

Upvotes: 3

Related Questions