Bar Chart
Variance Analysis Bar
Horizontal bars with standard deviation error.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
COLORS = {
'primary': '#6366F1',
'background': '#FFFFFF',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#F1F5F9',
}
samples = ['Sample 1', 'Sample 2', 'Sample 3', 'Sample 4', 'Sample 5']
means = [45, 52, 38, 60, 48]
std = [8, 12, 6, 15, 10]
y = np.arange(len(samples))
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
ax.barh(y, means, height=0.5, color=COLORS['primary'], alpha=0.85,
edgecolor='white', linewidth=2, zorder=3)
ax.errorbar(means, y, xerr=std, fmt='none', ecolor=COLORS['text'],
elinewidth=2, capsize=5, capthick=2, zorder=4)
for yi, (m, s) in zip(y, zip(means, std)):
ax.text(m + s + 3, yi, f'{m} ± {s}', ha='left', va='center',
fontsize=9, color=COLORS['text'])
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.xaxis.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_yticks(y)
ax.set_yticklabels(samples)
ax.set_xlim(0, 95)
ax.set_xlabel('Measurement', fontsize=10, color=COLORS['text'], labelpad=10)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Basic Charts
More Bar Chart examples
☕