3D Bar Chart

Memory Usage Y-Axis

3D bar chart showing memory usage projecting along Y

Output
Memory Usage Y-Axis
Python
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.colors import LinearSegmentedColormap
import matplotlib.cm as cm

fig = plt.figure(figsize=(12, 8), facecolor='white')
ax = fig.add_subplot(111, projection='3d')
ax.set_facecolor('white')

processes = 5
servers = 4
xpos = np.arange(processes)
zpos = np.arange(servers)
xpos, zpos = np.meshgrid(xpos, zpos)
xpos = xpos.flatten()
zpos = zpos.flatten()
ypos = np.zeros_like(xpos)

dx = 0.6
dz = 0.65
np.random.seed(3010)
dy = np.random.randint(512, 8192, size=20)

cmap = LinearSegmentedColormap.from_list('', ['#27D3F5', '#4927F5', '#F527B0'])
norm = plt.Normalize(min(dy), max(dy))
bar_colors = [cmap(norm(v)) for v in dy]

ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color=bar_colors, alpha=0.9, edgecolor='#000000', linewidth=0.3)

sm = cm.ScalarMappable(cmap=cmap, norm=norm)
sm.set_array([])
cbar = fig.colorbar(sm, ax=ax, shrink=0.5, aspect=15, pad=0.1)
cbar.set_label('MB', fontsize=10, color='#1f2937')
cbar.ax.tick_params(colors='#000000')

ax.set_xlabel('Process', fontsize=11, color='#1f2937', labelpad=10)
ax.set_ylabel('Memory (MB)', fontsize=11, color='#1f2937', labelpad=10)
ax.set_zlabel('Server', fontsize=11, color='#1f2937', labelpad=10)
ax.set_title('Memory Usage by Process', fontsize=14, color='#1f2937', fontweight='bold', pad=20)

ax.set_xticks(range(5))
ax.set_xticklabels(['Web', 'API', 'Worker', 'Cache', 'DB'], fontsize=8)
ax.set_zticks(range(4))
ax.set_zticklabels(['Srv-1', 'Srv-2', 'Srv-3', 'Srv-4'])
ax.tick_params(colors='#000000', labelsize=9)

ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
ax.xaxis.pane.set_edgecolor('#000000')
ax.yaxis.pane.set_edgecolor('#000000')
ax.zaxis.pane.set_edgecolor('#000000')
ax.grid(True, alpha=0.5, linewidth=0.5)
ax.xaxis._axinfo['grid']['color'] = '#000000'
ax.yaxis._axinfo['grid']['color'] = '#000000'
ax.zaxis._axinfo['grid']['color'] = '#000000'
ax.xaxis._axinfo['tick']['color'] = '#000000'
ax.yaxis._axinfo['tick']['color'] = '#000000'
ax.zaxis._axinfo['tick']['color'] = '#000000'
ax.xaxis.line.set_color('#000000')
ax.yaxis.line.set_color('#000000')
ax.zaxis.line.set_color('#000000')

ax.view_init(elev=20, azim=50)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

3D Charts

Did this help you?

Support PyLucid to keep it free & growing

Support