import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
from matplotlib.patches import Patch
import numpy as np
# 1. Original Data (FDAMDD, Unit: -logmmol/kg-bw/day. The Maximum Recommended Daily Dose (MRDD))
bins_mdd = np.array([-0.5, 0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0, 5.5, 6.0, 6.5])
freq_mdd = np.array([1.06, 3.91, 8.54, 12.27, 14.99, 18.51, 16.31, 12.70, 6.62, 2.29, 1.74, 0.42, 0.30, 0.13, 0.21])
# 2. Exact Gaussian Parameters
amp = 17.99
mean = 1.978
std = 1.116
def gauss_exact(x, a, mu, sigma):
return a * np.exp(-((x - mu)**2) / (2 * sigma**2))
x_fit = np.linspace(-1.0, 7.0, 500)
y_fit = gauss_exact(x_fit, amp, mean, std)
# 3. Color Function (Based on Power/Dose Cutoffs)
def get_colors(bins):
return ['#008000' if b < 1.0 else '#FFD700' if b <= 3.0 else '#B22222' for b in bins]
colors_hex = get_colors(bins_mdd)
face_colors = [mcolors.to_rgba(c, alpha=0.50) for c in colors_hex]
edge_colors = [mcolors.to_rgba(c, alpha=0.90) for c in colors_hex]
# 4. Create the chart
plt.figure(figsize=(7, 6))
# Draw bars and Gaussian line
plt.bar(bins_mdd, freq_mdd, width=0.45, color=face_colors, edgecolor=edge_colors, linewidth=1.5, zorder=2)
plt.plot(x_fit, y_fit, color='orange', linewidth=2.5, linestyle='-', alpha=0.8, zorder=3)
# 5. Tags and Titles
plt.xlabel(r'Maximum Recommended Daily Dose ($-\log_{10}$ mmol/kg/day)', fontsize=12)
plt.ylabel('% Frequency', fontsize=12)
plt.title('Maximum Recommended Daily Dose (MRDD)', fontsize=14)
# 6. Structured Legend
legend_elements = [
Patch(facecolor=mcolors.to_rgba('#008000', 0.5), edgecolor='#008000', label='High Dose Tolerance (< 1.0)'),
Patch(facecolor=mcolors.to_rgba('#FFD700', 0.5), edgecolor='#FFD700', label='Typical Therapeutic Range (1.0 - 3.0)'),
Patch(facecolor=mcolors.to_rgba('#B22222', 0.5), edgecolor='#B22222', label='High Potency / Strict Limit (> 3.0)'),
plt.Line2D([0], [0], color='orange', lw=2.5, alpha=0.8, label=f'Fit (Mean={mean}, SD={std})')
]
plt.legend(handles=legend_elements, loc='upper right', framealpha=0.95, fontsize=10)
plt.grid(axis='y', linestyle=':', alpha=0.7, zorder=0)
plt.xlim(-1.0, 7.0)
plt.ylim(0, 20)
plt.tight_layout()
plt.show()