how to draw a 3D voxel / volumetric plot
조회 수: 43 (최근 30일)
이전 댓글 표시
how to draw a 3D voxel / volumetric plot like this use matlab
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1438483/image.png)
this picture were drawn by python, the code sa below:
import matplotlib.pyplot as plt
import numpy as np
# This import registers the 3D projection, but is otherwise unused.
from mpl_toolkits.mplot3d import Axes3D # noqa: F401 unused import
# prepare some coordinates
x, y, z = np.indices((8, 8, 8))
# draw cuboids in the top left and bottom right corners, and a link between them
cube1 = (x < 3) & (y < 3) & (z < 3)
cube2 = (x >= 5) & (y >= 5) & (z >= 5)
link = abs(x - y) + abs(y - z) + abs(z - x) <= 2
# combine the objects into a single boolean array
voxels = cube1 | cube2 | link
# set the colors of each object
colors = np.empty(voxels.shape, dtype=object)
colors[link] = 'red'
colors[cube1] = 'blue'
colors[cube2] = 'green'
# and plot everything
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.voxels(voxels, facecolors=colors, edgecolor='k')
plt.show()
댓글 수: 0
답변 (1개)
Dyuman Joshi
2023년 7월 20일
이동: Matt J
2023년 7월 20일
댓글 수: 2
Dyuman Joshi
2023년 7월 21일
" How to associate the location of the goods with the goods and the color."
Do you have a data set to work with?
You can tie the center of the cube as the location corresponding to it.
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!