3D Voxels
Hollow Sphere Shell
Hollow spherical shell with amber-yellow gradient coloring.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
n = 15
x, y, z = np.indices((n, n, n))
cx, cy, cz = n // 2, n // 2, n // 2
# Octahedron: |x| + |y| + |z| <= r
r = 6
octahedron = (np.abs(x - cx) + np.abs(y - cy) + np.abs(z - cz)) <= r
# Gradient based on distance from center using coral palette
colors = np.empty(octahedron.shape + (4,), dtype=np.float32)
colors[..., 3] = 0
dist = np.abs(x - cx) + np.abs(y - cy) + np.abs(z - cz)
norm_dist = dist / r
# Coral #F5276C with brightness variation
colors[octahedron, 0] = 0.96
colors[octahedron, 1] = 0.15 + 0.2 * (1 - norm_dist[octahedron])
colors[octahedron, 2] = 0.42 + 0.2 * (1 - norm_dist[octahedron])
colors[octahedron, 3] = 0.7 + 0.25 * (1 - norm_dist[octahedron])
fig = plt.figure(figsize=(10, 8), facecolor='#020B14')
ax = fig.add_subplot(111, projection='3d', facecolor='#020B14')
ax.voxels(octahedron, 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('Octahedron 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
☕