Bar Chart

Bar Chart with CI

Bar chart with confidence interval error bars

Output
Bar Chart with CI
Python
import matplotlib.pyplot as plt
import numpy as np

treatments = ['Control', 'Drug A', 'Drug B', 'Drug C', 'Combo']
means = [45, 62, 58, 71, 78]
ci_lower = [4, 5, 6, 4, 5]
ci_upper = [4, 6, 5, 5, 6]

fig, ax = plt.subplots(figsize=(10, 6), facecolor='#0a0a0f')
ax.set_facecolor('#0a0a0f')

x = np.arange(len(treatments))
colors = ['#888888', '#27D3F5', '#6CF527', '#F5B027', '#F5276C']

bars = ax.bar(x, means, width=0.6, color=colors, edgecolor='none', alpha=0.9)
ax.errorbar(x, means, yerr=[ci_lower, ci_upper], fmt='none', color='white', capsize=5, capthick=2, linewidth=2)

ax.text(4, 85, '***', ha='center', color='#F5276C', fontsize=14, fontweight='bold')
ax.plot([0, 4], [82, 82], color='#444444', linewidth=1)

ax.set_xticks(x)
ax.set_xticklabels(treatments, color='white', fontsize=10)
ax.set_ylabel('Response (%)', color='#888888', fontsize=11)
ax.set_ylim(0, 95)

ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color('#333333')
ax.spines['bottom'].set_color('#333333')
ax.tick_params(axis='both', colors='#888888', labelsize=9)
ax.yaxis.grid(True, color='#1a1a2e', linewidth=0.5)
ax.set_axisbelow(True)

ax.set_title('Treatment Efficacy with 95% CI', color='white', fontsize=14, fontweight='bold', pad=15)
plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Basic Charts

Did this help you?

Support PyLucid to keep it free & growing

Support