Bar Chart
Dose Response
Dose-dependent response with p-value annotations.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# === STYLE CONFIG ===
COLORS = {
'bars': ['#6366F1', '#8B5CF6', '#A855F7', '#C084FC'],
'ns': '#94A3B8',
'sig': '#EF4444',
'background': '#FFFFFF',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#F1F5F9',
}
# === DATA ===
groups = ['Vehicle', 'Low Dose', 'Med Dose', 'High Dose']
means = [12, 18, 28, 45]
errors = [2, 3, 4, 5]
# p-values vs vehicle
pvals = [1, 0.08, 0.01, 0.001]
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 effect
for i, (m, c) in enumerate(zip(means, COLORS['bars'])):
ax.bar(i, m, width=0.55, color=c, alpha=0.15, zorder=1)
# Main bars
bars = ax.bar(x, means, width=0.45, color=COLORS['bars'], 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 annotations - with proper spacing
def pval_to_stars(p):
if p < 0.001: return '***'
elif p < 0.01: return '**'
elif p < 0.05: return '*'
else: return 'ns'
for i in range(1, len(groups)):
y_max = means[i] + errors[i] + 5 # More spacing
stars = pval_to_stars(pvals[i])
color = COLORS['sig'] if stars != 'ns' else COLORS['ns']
ax.text(i, y_max, stars, ha='center', va='bottom', fontsize=11,
fontweight='bold', color=color)
# === 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, 70) # More headroom for labels
ax.set_ylabel('Tumor Volume (mm³)', fontsize=10, color=COLORS['text'], labelpad=10)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Basic Charts
More Bar Chart examples
☕