ANOVA Boxplot
Drug Bioavailability ANOVA
Comparing drug absorption rates across different delivery methods.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as stats
np.random.seed(321)
# Bioavailability percentage
oral = np.random.normal(45, 12, 80)
sublingual = np.random.normal(72, 10, 80)
transdermal = np.random.normal(58, 14, 80)
injection = np.random.normal(95, 4, 80)
oral = np.clip(oral, 10, 80)
sublingual = np.clip(sublingual, 40, 95)
transdermal = np.clip(transdermal, 25, 90)
injection = np.clip(injection, 85, 100)
F_stat, p_value = stats.f_oneway(oral, sublingual, transdermal, injection)
fig, ax = plt.subplots(figsize=(12, 7), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')
colors = ['#C82909', '#F5B027', '#27D3F5', '#6CF527']
data = [oral, sublingual, transdermal, injection]
bp = ax.boxplot(data, positions=[1, 2, 3, 4], widths=0.6, patch_artist=True,
medianprops={'color': 'white', 'linewidth': 2},
whiskerprops={'color': '#555555', 'linewidth': 1.5},
capprops={'color': '#555555', 'linewidth': 1.5},
flierprops={'marker': 'o', 'markerfacecolor': '#444444', 'markersize': 4})
for patch, color in zip(bp['boxes'], colors):
patch.set_facecolor(color)
patch.set_alpha(0.7)
patch.set_edgecolor('white')
patch.set_linewidth(1.5)
labels = ['Oral', 'Sublingual', 'Transdermal', 'IV Injection']
# Therapeutic threshold
ax.axhline(y=60, color='#22c55e', linestyle='--', alpha=0.7, linewidth=1.5)
ax.text(4.45, 60, 'Therapeutic', fontsize=8, color='#22c55e', va='center')
# Mean and onset time
onset_times = ['30-60 min', '5-15 min', '2-4 hrs', 'Immediate']
for i, (d, onset, color) in enumerate(zip(data, onset_times, colors)):
ax.text(i+1, 5, f'μ={d.mean():.0f}% | {onset}', ha='center', fontsize=8, color=color)
# Stats header
stats_text = f"ANOVA: F={F_stat:.1f}, p<0.001 | Highest Bioavailability: IV Injection (95%)"
bbox = dict(boxstyle="round,pad=0.3", facecolor='#020B14', edgecolor='#6CF527', lw=2)
ax.text(0.5, 1.02, stats_text, transform=ax.transAxes, fontsize=9, color='white',
ha='center', va='bottom', fontfamily='monospace', bbox=bbox)
ax.set_xticks([1, 2, 3, 4])
ax.set_xticklabels(labels, fontsize=11, color='white')
ax.set_ylabel('Bioavailability (%)', fontsize=12, color='white', fontweight='500')
ax.set_title('Drug Delivery Method Comparison\nSystemic Bioavailability Study',
fontsize=14, color='white', fontweight='bold', pad=25)
ax.tick_params(colors='#888888')
for spine in ax.spines.values():
spine.set_color('#333333')
ax.yaxis.grid(True, color='#1a1a2e', linewidth=0.5)
ax.set_axisbelow(True)
ax.set_ylim(0, 105)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More ANOVA Boxplot examples
☕