3D Voxels
3D Voxel Bar Chart
Data visualization as 3D voxel bars with rainbow gradient.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# Bar chart data
n = 5
heights = [8, 12, 6, 10, 14]
# Full palette colors for each bar
palette = [
(0.96, 0.15, 0.42), # coral #F5276C
(0.15, 0.83, 0.96), # cyan #27D3F5
(0.96, 0.83, 0.15), # yellow #F5D327
(0.33, 0.08, 0.90), # deep_purple #5314E6
(0.42, 0.96, 0.15), # lime #6CF527
]
voxels = np.zeros((n * 3, n * 3, max(heights)), dtype=bool)
colors = np.empty(voxels.shape + (4,), dtype=np.float32)
colors[..., 3] = 0
for i, h in enumerate(heights):
x_start = i * 3
voxels[x_start:x_start+2, 1:3, :h] = True
colors[x_start:x_start+2, 1:3, :h, :3] = palette[i]
colors[x_start:x_start+2, 1:3, :h, 3] = 0.9
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('Category', fontsize=11, color='#94a3b8', labelpad=10)
ax.set_ylabel('Y', fontsize=11, color='#94a3b8', labelpad=10)
ax.set_zlabel('Value', fontsize=11, color='#94a3b8', labelpad=10)
ax.set_title('3D Voxel Bar Chart', 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
☕