Line & Scatter
KPI Performance Dashboard
Multi-metric dashboard with targets and performance indicators.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
# === STYLE CONFIG ===
COLORS = {
'actual': '#3B82F6',
'target': '#10B981',
'danger': '#EF4444',
'background': '#FFFFFF',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#F1F5F9',
}
# === DATA ===
months = np.arange(1, 13)
actual = [42, 45, 48, 52, 49, 55, 58, 62, 59, 65, 68, 72]
target = [45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67]
# === FIGURE ===
fig, ax = plt.subplots(figsize=(10, 6), dpi=100)
ax.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
# === PLOT ===
# Target line (dashed)
ax.plot(months, target, color=COLORS['target'], linewidth=2,
linestyle='--', label='Target', zorder=2)
# Actual performance
ax.plot(months, actual, color=COLORS['actual'], linewidth=2.5,
label='Actual', zorder=3)
ax.scatter(months, actual, color=COLORS['actual'], s=50,
edgecolors='white', linewidths=2, zorder=4)
# Highlight above/below target
for i in range(len(months)):
if actual[i] >= target[i]:
ax.scatter([months[i]], [actual[i]], color=COLORS['target'],
s=80, alpha=0.3, zorder=2)
else:
ax.scatter([months[i]], [actual[i]], color=COLORS['danger'],
s=80, alpha=0.3, zorder=2)
# Final value annotation
ax.annotate(f'{actual[-1]}', xy=(months[-1], actual[-1]),
xytext=(months[-1] + 0.3, actual[-1]),
fontsize=11, fontweight='bold', color=COLORS['actual'])
# === AXES ===
ax.set_xlim(0.5, 13)
ax.set_ylim(30, 80)
ax.set_xticks(months)
ax.set_xticklabels(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'])
ax.set_xlabel('Month', fontsize=10, color=COLORS['text'], labelpad=10)
ax.set_ylabel('Performance Score', fontsize=10, color=COLORS['text'], 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=1)
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.15),
ncol=2, frameon=False, fontsize=9, labelcolor=COLORS['text_muted'])
plt.tight_layout()
plt.show()
Library
Matplotlib
Category
Pairwise Data
More Line & Scatter examples
☕