3D Voxels
Capsule Pill Voxels
Pharmaceutical capsule shape with two-tone coral and cyan coloring.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
n = 20
voxels = np.zeros((n, n, 5), dtype=bool)
cx, cy = n // 2, n // 2
np.random.seed(42)
# Spiral galaxy pattern
for arm in range(2):
for t in np.linspace(0, 4 * np.pi, 100):
r = 1 + t * 0.5
angle = t + arm * np.pi
xx = int(cx + r * np.cos(angle) + np.random.randn() * 0.5)
yy = int(cy + r * np.sin(angle) + np.random.randn() * 0.5)
zz = 2 + int(np.random.randn() * 0.5)
if 0 <= xx < n and 0 <= yy < n and 0 <= zz < 5:
voxels[xx, yy, zz] = True
# Center bulge
for i in range(-2, 3):
for j in range(-2, 3):
if i*i + j*j <= 4:
voxels[cx+i, cy+j, :] = True
# Gradient from pink #F527B0 to deep_purple #5314E6
x_idx, y_idx, z_idx = np.indices((n, n, 5))
dist = np.sqrt((x_idx - cx)**2 + (y_idx - cy)**2)
max_dist = np.sqrt(2) * n / 2
colors = np.empty(voxels.shape + (4,), dtype=np.float32)
colors[..., 3] = 0
norm_dist = dist / max_dist
# F527B0 -> 5314E6
colors[voxels, 0] = 0.96 - 0.63 * norm_dist[voxels] # F5 to 53
colors[voxels, 1] = 0.15 - 0.07 * norm_dist[voxels] # 27 to 14
colors[voxels, 2] = 0.69 + 0.21 * norm_dist[voxels] # B0 to E6
colors[voxels, 3] = 0.9
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('Spiral Galaxy 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
More 3D Voxels examples
☕