3D Voxels
Layered Cube Explosion
Exploded view of layered cube with different colored layers.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
n = 12
x, y, z = np.indices((n, n, n))
# Multiple separated layers
layer1 = (z >= 0) & (z < 3) & (x >= 1) & (x < n-1) & (y >= 1) & (y < n-1)
layer2 = (z >= 4) & (z < 7) & (x >= 2) & (x < n-2) & (y >= 2) & (y < n-2)
layer3 = (z >= 8) & (z < 11) & (x >= 3) & (x < n-3) & (y >= 3) & (y < n-3)
layers = layer1 | layer2 | layer3
# CLAUDE.md colors
colors = np.zeros((n, n, n, 4), dtype=np.float32)
colors[layer1] = [0.15, 0.42, 0.96, 0.85] # Blue #276CF5
colors[layer2] = [0.96, 0.69, 0.15, 0.85] # Amber #F5B027
colors[layer3] = [0.15, 0.96, 0.69, 0.85] # Mint #27F5B0
fig = plt.figure(figsize=(10, 8), facecolor='#ffffff')
ax = fig.add_subplot(111, projection='3d', facecolor='#ffffff')
ax.voxels(layers, facecolors=colors, edgecolor='#33333320', linewidth=0.2)
ax.set_xlabel('X', fontsize=10, color='#374151', labelpad=10)
ax.set_ylabel('Y', fontsize=10, color='#374151', labelpad=10)
ax.set_zlabel('Z', fontsize=10, color='#374151', labelpad=10)
ax.set_title("Layered Cube Explosion", fontsize=14, color='#1f2937', fontweight='bold', pad=20)
ax.tick_params(colors='#6b7280', labelsize=8)
ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
ax.xaxis.pane.set_edgecolor('#e5e7eb')
ax.yaxis.pane.set_edgecolor('#e5e7eb')
ax.zaxis.pane.set_edgecolor('#e5e7eb')
ax.view_init(elev=25, azim=45)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
3D Charts
More 3D Voxels examples
☕