3D Voxels
Hollow Cube Structure
Hollow cube frame structure showing edges only in blue-purple gradient.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# Prepare coordinates
n = 10
x, y, z = np.indices((n, n, n))
# Hollow cube (shell only)
outer = (x == 0) | (x == n-1) | (y == 0) | (y == n-1) | (z == 0) | (z == n-1)
inner = (x > 1) & (x < n-2) & (y > 1) & (y < n-2) & (z > 1) & (z < n-2)
shell = outer & ~inner
# Color gradient using yellow #F5D327 and amber #F5B027
colors = np.empty(shell.shape + (4,), dtype=np.float32)
norm_z = z / (n - 1)
colors[..., 0] = 0.96 # R
colors[..., 1] = 0.83 - 0.14 * norm_z # G (from D3 to B0)
colors[..., 2] = 0.15 + 0.12 * norm_z # B
colors[..., 3] = 0.85
fig = plt.figure(figsize=(10, 8), facecolor='#ffffff')
ax = fig.add_subplot(111, projection='3d', facecolor='#ffffff')
ax.voxels(shell, facecolors=colors, edgecolor='#33333330', linewidth=0.2)
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("Hollow Cube Structure", 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
☕