3D Bar Chart

Drug Trial Response

Patient response rates across dosage levels and treatment phases

Output
Drug Trial Response
Python
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.colors import LinearSegmentedColormap

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

dosages = 4
phases = 5
xpos = np.arange(dosages)
zpos = np.arange(phases)
xpos, zpos = np.meshgrid(xpos, zpos)
xpos = xpos.flatten()
zpos = zpos.flatten()
ypos = np.zeros_like(xpos)

dx = 0.65
dz = 0.55
np.random.seed(111)
dy = np.clip(np.random.beta(3, 2, size=20) * 100 + zpos * 5, 0, 100)

cmap = LinearSegmentedColormap.from_list('neon', ['#F5276C', '#F527B0', '#4927F5', '#27D3F5'])
norm = plt.Normalize(0, 100)
colors = [cmap(norm(v)) for v in dy]

ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color=colors, alpha=0.9, edgecolor='#1a1a2e', linewidth=0.4)

ax.set_xlabel('Dosage', fontsize=11, color='white', labelpad=12)
ax.set_ylabel('Response (%)', fontsize=11, color='white', labelpad=12)
ax.set_zlabel('Phase', fontsize=11, color='white', labelpad=10)
ax.set_title('Clinical Trial Response Matrix', fontsize=14, color='white', fontweight='bold', pad=20)

ax.set_xticks(range(4))
ax.set_xticklabels(['10mg', '25mg', '50mg', '100mg'], fontsize=8, color='#888888')
ax.set_zticks(range(5))
ax.set_zticklabels(['Week 1', 'Week 2', 'Week 4', 'Week 8', 'Week 12'], fontsize=7, color='#888888')
ax.tick_params(colors='#888888', labelsize=9)

ax.xaxis.pane.fill = False
ax.yaxis.pane.fill = False
ax.zaxis.pane.fill = False
ax.xaxis.pane.set_edgecolor('#333333')
ax.yaxis.pane.set_edgecolor('#333333')
ax.zaxis.pane.set_edgecolor('#333333')
ax.grid(True, alpha=0.2, linewidth=0.5)

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

Matplotlib

Category

3D Charts

Did this help you?

Support PyLucid to keep it free & growing

Support