3D Voxels
3D Wave Pattern Voxels
Sinusoidal wave visualization using voxels with teal gradient.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
n = 20
x, y = np.indices((n, n))
# Sine wave height pattern
heights = (4 * np.sin(x * 0.5) * np.cos(y * 0.5) + 5).astype(int)
voxels = np.zeros((n, n, 10), dtype=bool)
for i in range(n):
for j in range(n):
voxels[i, j, :heights[i, j]] = True
# Gradient from yellow_lime #D3F527 to cyan #27D3F5
z_idx = np.indices((n, n, 10))[2]
colors = np.empty(voxels.shape + (4,), dtype=np.float32)
colors[..., 3] = 0
norm_z = z_idx / 9
# D3F527 -> 27D3F5
colors[voxels, 0] = 0.83 - 0.56 * norm_z[voxels] # D3 to 27
colors[voxels, 1] = 0.96 - 0.13 * norm_z[voxels] # F5 to D3
colors[voxels, 2] = 0.15 + 0.81 * norm_z[voxels] # 27 to F5
colors[voxels, 3] = 0.88
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.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('3D Wave Pattern 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
☕