3D Voxels
Hourglass Voxels
Two cones meeting at the center forming an hourglass with teal gradient.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
n = 12
voxels = np.zeros((n, n, n), dtype=bool)
# Stacked cubes of decreasing size
sizes = [6, 4, 2]
colors_list = [
(0.78, 0.16, 0.04), # red #C82909
(0.96, 0.83, 0.15), # yellow #F5D327
(0.33, 0.08, 0.90), # deep_purple #5314E6
]
colors = np.empty(voxels.shape + (4,), dtype=np.float32)
colors[..., 3] = 0
z_offset = 0
for i, size in enumerate(sizes):
margin = (n - size) // 2
voxels[margin:margin+size, margin:margin+size, z_offset:z_offset+size] = True
colors[margin:margin+size, margin:margin+size, z_offset:z_offset+size, :3] = colors_list[i]
colors[margin:margin+size, margin:margin+size, z_offset:z_offset+size, 3] = 0.9
z_offset += size
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.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('Stacked Cubes', 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
☕