Error Bar Chart
Dose-Response Curve with EC50
Pharmacological dose-response curve showing drug efficacy with fitted sigmoid and EC50 determination.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(42)
# Drug dosage response
dosage = np.array([0.1, 0.5, 1, 2, 5, 10, 20, 50, 100])
response = np.array([5, 15, 28, 45, 62, 78, 88, 94, 96])
response_err = np.array([2, 3, 4, 5, 6, 5, 4, 3, 2])
fig, ax = plt.subplots(figsize=(10, 6), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')
ax.errorbar(dosage, response, yerr=response_err, fmt='o', color='#F5B027',
ecolor='#F5B027', elinewidth=1.5, capsize=5, capthick=1.5,
markersize=10, markerfacecolor='#F5B027', markeredgecolor='white',
markeredgewidth=1.5, label='Observed', alpha=0.9)
# Fit sigmoid curve
from scipy.optimize import curve_fit
def sigmoid(x, L, k, x0):
return L / (1 + np.exp(-k * (np.log10(x) - x0)))
popt, _ = curve_fit(sigmoid, dosage, response, p0=[100, 2, 0.5], maxfev=5000)
x_fit = np.logspace(-1, 2, 100)
y_fit = sigmoid(x_fit, *popt)
ax.plot(x_fit, y_fit, '--', color='#27D3F5', linewidth=2, label='Fitted Curve', alpha=0.8)
ax.fill_between(x_fit, y_fit - 5, y_fit + 5, color='#27D3F5', alpha=0.1)
# EC50 line
ec50 = 10 ** popt[2]
ax.axhline(y=50, color='#F5276C', linestyle=':', linewidth=1.5, alpha=0.7)
ax.axvline(x=ec50, color='#F5276C', linestyle=':', linewidth=1.5, alpha=0.7)
ax.annotate(f'EC50 = {ec50:.1f} μM', xy=(ec50, 50), xytext=(ec50*3, 40),
color='#F5276C', fontsize=10, fontweight='500',
arrowprops=dict(arrowstyle='->', color='#F5276C', lw=1.5))
ax.set_xscale('log')
ax.set_xlabel('Drug Concentration (μM)', fontsize=11, color='white', fontweight='500')
ax.set_ylabel('Response (%)', fontsize=11, color='white', fontweight='500')
ax.set_title('Dose-Response Curve with EC50 Estimation', fontsize=14,
color='white', fontweight='bold', pad=15)
ax.legend(facecolor='#1a1a2e', edgecolor='#333', labelcolor='white', fontsize=10)
ax.tick_params(colors='#94a3b8', labelsize=9)
ax.set_ylim(0, 110)
ax.grid(True, alpha=0.2, color='#4a4a6a')
for spine in ax.spines.values():
spine.set_color('#333333')
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Statistical
More Error Bar Chart examples
☕