Bar Chart
Treatment Comparison
Control vs treatments with significance brackets.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# === STYLE CONFIG ===
COLORS = {
'control': '#94A3B8',
'treatment': '#6366F1',
'significant': '#EF4444',
'background': '#FFFFFF',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#F1F5F9',
}
# === DATA ===
groups = ['Control', 'Treatment A', 'Treatment B', 'Treatment C']
means = [45, 62, 58, 72]
errors = [5, 6, 4, 7]
significant = [False, True, False, True] # vs Control
colors = [COLORS['control']] + [COLORS['treatment']]*3
x = np.arange(len(groups))
# === FIGURE ===
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
# === PLOT ===
# Glow
for i in range(len(groups)):
ax.bar(i, means[i], width=0.55, color=colors[i], alpha=0.15, zorder=1)
# Bars
bars = ax.bar(x, means, width=0.45, color=colors, alpha=0.85,
edgecolor='white', linewidth=2, zorder=3)
# Error bars
ax.errorbar(x, means, yerr=errors, fmt='none', ecolor=COLORS['text'],
elinewidth=2, capsize=6, capthick=2, zorder=4)
# Significance brackets
def add_significance(ax, x1, x2, y, text):
h = 3
ax.plot([x1, x1, x2, x2], [y, y+h, y+h, y], color=COLORS['significant'], lw=1.5)
ax.text((x1+x2)/2, y+h+1, text, ha='center', va='bottom',
fontsize=10, fontweight='bold', color=COLORS['significant'])
# Add significance markers
for i, sig in enumerate(significant):
if sig and i > 0:
add_significance(ax, 0, i, max(means[0], means[i]) + errors[max(0,i)] + 5, '***')
# === STYLING ===
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['left'].set_color(COLORS['grid'])
ax.spines['bottom'].set_color(COLORS['grid'])
ax.yaxis.grid(True, color=COLORS['grid'], linewidth=1, zorder=0)
ax.set_axisbelow(True)
ax.tick_params(axis='both', colors=COLORS['text_muted'], labelsize=9, length=0, pad=8)
ax.set_xticks(x)
ax.set_xticklabels(groups)
ax.set_ylim(0, 100)
ax.set_ylabel('Response (%)', fontsize=10, color=COLORS['text'], labelpad=10)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Basic Charts
More Bar Chart examples
☕