Filter löschen
Filter löschen

how to draw a 3D voxel / volumetric plot

43 Ansichten (letzte 30 Tage)
jin yong
jin yong am 20 Jul. 2023
Kommentiert: Dyuman Joshi am 21 Jul. 2023
how to draw a 3D voxel / volumetric plot like this use matlab
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()

Antworten (1)

Dyuman Joshi
Dyuman Joshi am 20 Jul. 2023
Verschoben: Matt J am 20 Jul. 2023
Check out patch or PLOTCUBE
  2 Kommentare
jin yong
jin yong am 21 Jul. 2023
Suppose this is a warehouse shelf, and each small cube represents a location where the goods are placed. Now there are three kinds of goods: beef, biscuits and drinks. Beef is shown in red, biscuits in green, drinks in yellow, and no goods on the shelves in white. How to associate the location of the goods with the goods and the color. The location of the goods is represented by the color of the small cube, and an index is established between the goods and the color and the small cube.
voxel is a function to plot 3D cube
figure
axis([0 10 0 5 0 5]);
view(-37.5,30)
for i=0:4:10
for j=0:4
for k=0:5
voxel([i+0,j+0,k],[1 1 1],'w',0.7)
end
end
end
Dyuman Joshi
Dyuman Joshi am 21 Jul. 2023
" 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by