Line & Scatter

Annotated Key Points

Chart with modern styled annotations highlighting key data points.

Output
Annotated Key Points
Python
import matplotlib.pyplot as plt
import numpy as np

# === STYLE CONFIG ===
COLORS = {
    'line': '#10B981',       # Emerald
    'highlight': '#F59E0B',  # Amber
    'background': '#0F172A',
    'card': '#1E293B',
    'text': '#E2E8F0',
    'text_muted': '#94A3B8',
    'grid': '#334155',
}

# === DATA ===
x = np.linspace(0, 10, 100)
y = 2 + 3 * np.sin(0.8 * x) + 0.5 * x

# Key points
peak_idx = np.argmax(y)
peak_x, peak_y = x[peak_idx], y[peak_idx]

# === FIGURE ===
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])

# === PLOT ===
# Glow effect on line
for lw, alpha in [(8, 0.05), (5, 0.1), (2.5, 1.0)]:
    ax.plot(x, y, color=COLORS['line'], linewidth=lw, alpha=alpha)

# Highlight point with glow
for s, alpha in [(400, 0.1), (250, 0.2), (100, 0.4)]:
    ax.scatter([peak_x], [peak_y], s=s, color=COLORS['highlight'], alpha=alpha)
ax.scatter([peak_x], [peak_y], s=50, color=COLORS['highlight'], 
           edgecolors='white', linewidths=2, zorder=5)

# Modern annotation box
bbox_props = dict(boxstyle='round,pad=0.5,rounding_size=0.3', 
                  facecolor=COLORS['card'], edgecolor=COLORS['grid'],
                  alpha=0.95, linewidth=1)
ax.annotate(f'Peak: {peak_y:.1f}', xy=(peak_x, peak_y), 
            xytext=(peak_x + 1.5, peak_y + 1),
            fontsize=10, color=COLORS['text'], fontweight='500',
            bbox=bbox_props,
            arrowprops=dict(arrowstyle='->', color=COLORS['text_muted'], lw=1.5))

# === AXES ===
ax.set_xlim(0, 10)
ax.set_ylim(0, 10)
ax.set_xlabel('Time', fontsize=10, color=COLORS['text'], labelpad=10)
ax.set_ylabel('Value', fontsize=10, color=COLORS['text'], labelpad=10)

# === STYLING ===
for spine in ax.spines.values():
    spine.set_visible(False)

ax.yaxis.grid(True, color=COLORS['grid'], linewidth=0.5, alpha=0.3)
ax.xaxis.grid(False)
ax.set_axisbelow(True)
ax.tick_params(axis='both', colors=COLORS['text'], labelsize=9, length=0, pad=8)

plt.tight_layout()
plt.show()
Library

Matplotlib

Category

Pairwise Data

Did this help you?

Support PyLucid to keep it free & growing

Support