Note
Go to the endto download the full example code.
3D voxel / volumetric plot#
Demonstrates plotting 3D volumetric objects withAxes3D.voxels.
importmatplotlib.pyplotaspltimportnumpyasnp# prepare some coordinatesx,y,z=np.indices((8,8,8))# draw cuboids in the top left and bottom right corners, and a link between# themcube1=(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 arrayvoxelarray=cube1|cube2|link# set the colors of each objectcolors=np.empty(voxelarray.shape,dtype=object)colors[link]='red'colors[cube1]='blue'colors[cube2]='green'# and plot everythingax=plt.figure().add_subplot(projection='3d')ax.voxels(voxelarray,facecolors=colors,edgecolor='k')plt.show()
