3D Voxels
Voxel Octahedron
Diamond-shaped octahedron with cyan-blue gradient coloring.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
n = 13
x, y, z = np.indices((n, n, n))
# Octahedron (Manhattan distance)
center = n // 2
octahedron = (np.abs(x - center) + np.abs(y - center) + np.abs(z - center)) <= center
# Gradient: purple #4927F5 to blue #276CF5
colors = np.empty(octahedron.shape + (4,), dtype=np.float32)
norm_z = z / (n - 1)
colors[..., 0] = 0.29 - 0.14 * norm_z # R (49 to 27)
colors[..., 1] = 0.15 + 0.27 * norm_z # G (27 to 6C)
colors[..., 2] = 0.96 # B
colors[..., 3] = 0.85
fig = plt.figure(figsize=(10, 8), facecolor='#ffffff')
ax = fig.add_subplot(111, projection='3d', facecolor='#ffffff')
ax.voxels(octahedron, facecolors=colors, edgecolor='#33333318', 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 Octahedron", 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
☕