3D Voxels
Voxel Sphere
Discrete sphere approximation using voxels with mint-teal coloring.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# Prepare coordinates
n = 15
x, y, z = np.indices((n, n, n))
# Center and radius
cx, cy, cz = n // 2, n // 2, n // 2
radius = n // 2 - 1
# Sphere condition
sphere = (x - cx)**2 + (y - cy)**2 + (z - cz)**2 <= radius**2
# Color gradient: mint #27F5B0 -> cyan #27D3F5
colors = np.empty(sphere.shape + (4,), dtype=np.float32)
dist = np.sqrt((x - cx)**2 + (y - cy)**2 + (z - cz)**2) / radius
colors[..., 0] = 0.15 # R
colors[..., 1] = 0.96 - 0.13 * dist # G (F5 to D3)
colors[..., 2] = 0.69 + 0.27 * dist # B (B0 to F5)
colors[..., 3] = 0.85
fig = plt.figure(figsize=(10, 8), facecolor='#ffffff')
ax = fig.add_subplot(111, projection='3d', facecolor='#ffffff')
ax.voxels(sphere, facecolors=colors, edgecolor='#33333320', linewidth=0.15)
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("Voxel Sphere", 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
☕