3D Voxels

Building Blocks Stack

Stacked building blocks with vibrant multi-color pattern.

Output
Building Blocks Stack
Python
import matplotlib.pyplot as plt
import numpy as np

n = 17
x, y, z = np.indices((n, n, n))
cx, cy, cz = n // 2, n // 2, n // 2

# Hollow sphere
r_outer = 7
r_inner = 5
dist = np.sqrt((x - cx)**2 + (y - cy)**2 + (z - cz)**2)
sphere = (dist <= r_outer) & (dist >= r_inner)

# Gradient from dark_red #9C2007 to orange #F54927
colors = np.empty(sphere.shape + (4,), dtype=np.float32)
colors[..., 3] = 0

norm_dist = (dist - r_inner) / (r_outer - r_inner)
# 9C2007 -> F54927
colors[sphere, 0] = 0.61 + 0.35 * norm_dist[sphere]  # 9C to F5
colors[sphere, 1] = 0.13 + 0.16 * norm_dist[sphere]  # 20 to 49
colors[sphere, 2] = 0.03 + 0.12 * norm_dist[sphere]  # 07 to 27
colors[sphere, 3] = 0.85

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

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

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('Hollow Sphere Voxels', 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