3D Voxels
3D Checkerboard Cube
Three-dimensional checkerboard pattern with alternating cyan and coral voxels.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# Create checkerboard pattern
n = 8
x, y, z = np.indices((n, n, n))
checker = ((x + y + z) % 2 == 0)
# Colors: yellow #F5D327 and deep_purple #5314E6
colors = np.empty(checker.shape + (4,), dtype=np.float32)
colors[..., 3] = 0
# Yellow squares
yellow_mask = checker & ((x + y + z) % 2 == 0)
colors[yellow_mask, 0] = 0.96 # F5
colors[yellow_mask, 1] = 0.83 # D3
colors[yellow_mask, 2] = 0.15 # 27
colors[yellow_mask, 3] = 0.9
# Deep purple squares (inverse)
purple_mask = ~checker
colors[purple_mask, 0] = 0.33 # 53
colors[purple_mask, 1] = 0.08 # 14
colors[purple_mask, 2] = 0.90 # E6
colors[purple_mask, 3] = 0.9
fig = plt.figure(figsize=(10, 8), facecolor='#020B14')
ax = fig.add_subplot(111, projection='3d', facecolor='#020B14')
ax.voxels(checker | ~checker, 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('3D Checkerboard Cube', 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
☕