import matplotlib.pyplot as plt
from matplotlib.patches import Patch
import numpy as np
from scipy.interpolate import make_interp_spline
# 1. hERG Inhibitor data (Probability of IC50 < 1uM)
bin_centers = [0.0, 0.05, 0.10, 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, 0.90]
frequencies = [37.78, 23.67, 8.94, 5.54, 5.14, 3.16, 2.47, 2.55, 1.46,
1.54, 1.62, 1.38, 1.46, 1.05, 0.81, 0.69, 0.36, 0.32, 0.08]
# 2. Smoothing
x_smooth = np.linspace(min(bin_centers), max(bin_centers), 300)
spl = make_interp_spline(bin_centers, frequencies, k=3)
y_smooth = spl(x_smooth)
y_smooth = np.clip(y_smooth, 0, None) # evita valores negativos
# 3. Colors (Strict traffic light)
colors = []
for val in bin_centers:
if val < 0.15:
colors.append('mediumseagreen')
elif val < 0.4:
colors.append('gold')
else:
colors.append('firebrick')
# 4. Create the chart
plt.figure(figsize=(7, 6))
# Bars
plt.bar(bin_centers, frequencies, width=0.04, color=colors, edgecolor='black', alpha=0.8)
# 5. Labels and Titles
plt.xlabel('Probability of hERG Inhibition (IC50 < 1µM)', fontsize=12)
plt.ylabel('% Frequency', fontsize=12)
plt.title('hERG Cardiotoxicity: The "Showstopper" Filter', fontsize=14)
# Axes settings
plt.xticks(np.arange(0.0, 1.0, 0.1))
plt.xlim(-0.05, 0.95)
plt.ylim(0, 40)
# 6. Legend
legend_elements = [
Patch(facecolor='mediumseagreen', edgecolor='black', label='Safe (Low Risk)'),
Patch(facecolor='gold', edgecolor='black', label='Warning (Safety Monitoring Needed)'),
Patch(facecolor='firebrick', edgecolor='black', label='High Risk (Attrition Driver)'),
]
plt.legend(handles=legend_elements, loc='upper right', framealpha=0.95, fontsize=10)
plt.grid(axis='y', linestyle='--', alpha=0.5)
plt.tight_layout()
plt.show()