简体   繁体   中英

Visualizing a 3d numpy array of 1's and 0's

Alright so guys I have this 3d array of 1's and 0's which is supposed to represent a 3d object. 0 means that there is nothing there. 1 means that the objects exists in that co-ordinate. I need to display the 3d-object on my screen. It would be ideal for me to have a discrete 3 dimensoinal graph with value depending colors. I tried looking into glumpy and vispy but the documentation page seems to be down right now.

I made a pull request to matplotlib that does exactly this , adding the ax3d.voxels function. Unfortunately, it hasn't been reviewed fully yet.

Update: This made it into matplotlib 2.1

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

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# your real data here - some 3d boolean array
x, y, z = np.indices((10, 10, 10))
voxels = (x == y) | (y == z)

ax.voxels(voxels)

plt.show()

结果图

Use np.where to extract the coordinates, and matplotlib for the 3D plot.

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

data = np.zeros(shape=(20, 20, 20), dtype=np.bool_)
np.fill_diagonal(data, True)

fig = plt.figure()
Axes3D(fig).plot_wireframe(*np.nonzero(data))
plt.show()

This plots a basic 3D wireframe according to where the ones appeared in the matrix. You may wish to use plot_surface or scatter in place of plot_wireframe . See the documentation for more information.

Could you save the x,y,z coordinates of each '1' point to a file and display it with cloudcompare or meshlab ?

Cloudcompare will even let you store other values after each point and choose how to map these onto colour

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM