import matplotlib.pyplot as plt
from matplotlib.patches import Patch
from matplotlib.lines import Line2D
import numpy as np
# 1. CLr (Renal Clearance Mechanism) Data
x = [0.15, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50,
0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85]
y = [0.04, 1.33, 0.61, 4.41, 5.46, 7.69, 7.93, 10.56,
12.14, 15.09, 13.96, 11.12, 7.36, 2.14, 0.16]
# 2. Gaussian Parameters (Provided)
amplitude = 13.97
mean = 0.5786
sd = 0.1456
# Convert to numpy array
x_array = np.array(x)
# Generate smooth curve
x_smooth = np.linspace(min(x_array), max(x_array), 300)
y_smooth = amplitude * np.exp(-0.5 * ((x_smooth - mean) / sd)**2)
# 3. Colors (Cutoff point at 0.5)
colors = np.where(x_array < 0.5, 'gold', 'steelblue')
# 4. Create the chart
plt.figure(figsize=(7, 6))
# A. Bars
plt.bar(x, y, width=0.04, color=colors, edgecolor='black',
alpha=0.7, label='Data Frequency')
# B. Gaussian curve
plt.plot(x_smooth, y_smooth, color='darkorange',
linewidth=2, label='Gaussian Fit')
# 5. Labels and Title
plt.xlabel('Renal Clearance Mechanism Probability (0=Reabsorption, 1=Secretion)', fontsize=12)
plt.ylabel('% Frequency', fontsize=12)
plt.title('Renal Clearance (CLr) Mechanism Prediction', fontsize=14)
# Axes settings
plt.xticks(np.arange(0.1, 0.95, 0.1))
plt.xlim(0.1, 0.9)
plt.ylim(0, 16)
# 6. Legend
legend_elements = [
Patch(facecolor='gold', edgecolor='black', alpha=0.7,
label='Net Reabsorption (Score < 0.5)'),
Patch(facecolor='steelblue', edgecolor='black', alpha=0.7,
label='Net Secretion (Score ≥ 0.5)'),
Line2D([0], [0], color='darkorange', lw=2.5,
label=f'Fit (Mean={mean}, SD={sd})'),
]
plt.legend(handles=legend_elements, loc='upper left', framealpha=0.9)
plt.grid(axis='y', linestyle='--', alpha=0.5)
plt.tight_layout()
plt.show()