3D Voxels

Nested Hollow Cubes

Concentric hollow cube shells with multi-color layers.

Output
Nested Hollow Cubes
Python
import matplotlib.pyplot as plt
import numpy as np

n = 15
voxels = np.zeros((n, n, n), dtype=bool)

# Outer cube shell
voxels[0, :, :] = True
voxels[n-1, :, :] = True
voxels[:, 0, :] = True
voxels[:, n-1, :] = True
voxels[:, :, 0] = True
voxels[:, :, n-1] = True

# Inner cube shell
m = 5
s = (n - m) // 2
voxels[s, s:s+m, s:s+m] = True
voxels[s+m-1, s:s+m, s:s+m] = True
voxels[s:s+m, s, s:s+m] = True
voxels[s:s+m, s+m-1, s:s+m] = True
voxels[s:s+m, s:s+m, s] = True
voxels[s:s+m, s:s+m, s+m-1] = True

# Colors: amber #F5B027 outer, blue #276CF5 inner
colors = np.empty(voxels.shape + (4,), dtype=np.float32)
colors[..., 3] = 0

x, y, z = np.indices((n, n, n))
outer = (x == 0) | (x == n-1) | (y == 0) | (y == n-1) | (z == 0) | (z == n-1)

# Outer - amber
colors[voxels & outer, 0] = 0.96
colors[voxels & outer, 1] = 0.69
colors[voxels & outer, 2] = 0.15
colors[voxels & outer, 3] = 0.7

# Inner - blue
inner = ~outer
colors[voxels & inner, 0] = 0.15
colors[voxels & inner, 1] = 0.42
colors[voxels & inner, 2] = 0.96
colors[voxels & inner, 3] = 0.95

fig = plt.figure(figsize=(10, 8), facecolor='#020B14')
ax = fig.add_subplot(111, projection='3d', facecolor='#020B14')

ax.voxels(voxels, facecolors=colors, edgecolors='#1e293b', linewidth=0.3)

ax.set_xlabel('X', fontsize=11, color='#94a3b8', labelpad=10)
ax.set_ylabel('Y', fontsize=11, color='#94a3b8', labelpad=10)
ax.set_zlabel('Z', fontsize=11, color='#94a3b8', labelpad=10)
ax.set_title('Nested Hollow Cubes', fontsize=14, color='white', fontweight='bold', pad=20)

ax.tick_params(colors='#64748b', labelsize=8)
ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
ax.xaxis.pane.set_edgecolor('#1e293b')
ax.yaxis.pane.set_edgecolor('#1e293b')
ax.zaxis.pane.set_edgecolor('#1e293b')
ax.grid(True, alpha=0.2, color='#475569')

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

3D Charts

Did this help you?

Support PyLucid to keep it free & growing

Support