Line & Scatter
Points with Error Bars
Data points with vertical and horizontal error bars.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# === STYLE CONFIG ===
COLORS = {
'points': '#10B981', # Emerald
'errors': '#64748B', # Slate
'background': '#FAFBFC',
'text_muted': '#64748B',
'grid': '#E2E8F0',
}
# === DATA ===
np.random.seed(42)
x = np.array([1, 2, 3, 4, 5, 6, 7, 8])
y = np.array([2.3, 3.1, 4.5, 4.2, 5.8, 6.1, 7.2, 8.0])
y_err = np.random.uniform(0.3, 0.8, len(x))
x_err = np.random.uniform(0.1, 0.3, len(x))
# === FIGURE ===
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
# === PLOT ===
ax.errorbar(x, y, yerr=y_err, xerr=x_err,
fmt='o', color=COLORS['points'],
ecolor=COLORS['errors'], elinewidth=1.5, capsize=4, capthick=1.5,
markersize=10, markeredgecolor='white', markeredgewidth=2,
label='Measurements', zorder=3)
# Trend line
z = np.polyfit(x, y, 1)
p = np.poly1d(z)
ax.plot(x, p(x), '--', color=COLORS['errors'], linewidth=1.5,
alpha=0.7, label='Trend', zorder=2)
# === AXES ===
ax.set_xlim(0, 9)
ax.set_ylim(0, 10)
ax.set_xlabel('X', fontsize=10, color=COLORS['text_muted'], labelpad=10)
ax.set_ylabel('Y', fontsize=10, color=COLORS['text_muted'], labelpad=10)
# === STYLING ===
for spine in ['top', 'right']:
ax.spines[spine].set_visible(False)
for spine in ['bottom', 'left']:
ax.spines[spine].set_color(COLORS['grid'])
ax.yaxis.grid(True, color=COLORS['grid'], linewidth=0.5, alpha=0.7)
ax.xaxis.grid(False)
ax.set_axisbelow(True)
ax.tick_params(axis='both', colors=COLORS['text_muted'], labelsize=9, length=0, pad=8)
ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.12),
ncol=2, frameon=False, fontsize=9, labelcolor=COLORS['text_muted'])
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Line & Scatter examples
☕