Line & Scatter
Error Bars with Trend
Data points with error bars connected by a trend line.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# === STYLE CONFIG ===
COLORS = {
'line': '#3B82F6',
'points': '#3B82F6',
'error': '#93C5FD',
'background': '#FAFBFC',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#E2E8F0',
}
# === DATA ===
np.random.seed(42)
x = np.arange(1, 9)
y = 1.5 + 0.8 * x + np.random.normal(0, 0.3, len(x))
yerr = np.random.uniform(0.3, 0.6, len(x))
# === FIGURE ===
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
# === PLOT ===
# Line connecting points
ax.plot(x, y, '-', color=COLORS['line'], linewidth=2, alpha=0.5, zorder=1)
# Error bars with points
ax.errorbar(x, y, yerr=yerr, fmt='o', color=COLORS['points'],
ecolor=COLORS['error'], elinewidth=2, capsize=5, capthick=2,
markersize=10, markeredgecolor='white', markeredgewidth=2, zorder=2)
# === AXES ===
ax.set_xlim(0, 9)
ax.set_ylim(0, 10)
ax.set_xlabel('Time', fontsize=10, color=COLORS['text_muted'], labelpad=10)
ax.set_ylabel('Value', fontsize=10, color=COLORS['text_muted'], labelpad=10)
# === 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=0.5, alpha=0.7)
ax.set_axisbelow(True)
ax.tick_params(axis='both', colors=COLORS['text_muted'], labelsize=9, length=0, pad=8)
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Line & Scatter examples
☕