Scatter Plot
Dual Axis Timeline
Two metrics on separate Y-axes.
Output
Python
import matplotlib.pyplot as plt
import numpy as np
COLORS = {
'primary': '#3B82F6',
'secondary': '#F59E0B',
'background': '#FFFFFF',
'text': '#1E293B',
'text_muted': '#64748B',
'grid': '#F1F5F9',
}
np.random.seed(42)
x = np.arange(1, 13)
y1 = 50 + np.cumsum(np.random.normal(2, 3, 12))
y2 = 5 + np.cumsum(np.random.normal(0.5, 0.8, 12))
fig, ax1 = plt.subplots(figsize=(10, 6), dpi=100)
ax1.set_facecolor(COLORS['background'])
fig.patch.set_facecolor(COLORS['background'])
ax2 = ax1.twinx()
ax1.plot(x, y1, color=COLORS['primary'], linewidth=2, zorder=2)
ax1.scatter(x, y1, s=150, c=COLORS['primary'], alpha=0.2, zorder=3)
ax1.scatter(x, y1, s=60, c=COLORS['primary'], alpha=0.9,
edgecolors='white', linewidths=1.5, label='Revenue', zorder=4)
ax2.plot(x, y2, color=COLORS['secondary'], linewidth=2, zorder=2)
ax2.scatter(x, y2, s=150, c=COLORS['secondary'], alpha=0.2, zorder=3)
ax2.scatter(x, y2, s=60, c=COLORS['secondary'], alpha=0.9,
edgecolors='white', linewidths=1.5, label='Growth Rate', zorder=4)
ax1.spines['top'].set_visible(False)
ax1.spines['left'].set_color(COLORS['primary'])
ax1.spines['bottom'].set_color(COLORS['grid'])
ax1.spines['right'].set_visible(False)
ax2.spines['top'].set_visible(False)
ax2.spines['right'].set_color(COLORS['secondary'])
ax2.spines['left'].set_visible(False)
ax2.spines['bottom'].set_visible(False)
ax1.tick_params(axis='y', colors=COLORS['primary'], labelsize=9, length=0, pad=8)
ax1.tick_params(axis='x', colors=COLORS['text_muted'], labelsize=9, length=0, pad=8)
ax2.tick_params(axis='y', colors=COLORS['secondary'], labelsize=9, length=0, pad=8)
ax1.set_ylabel('Revenue ($M)', fontsize=10, color=COLORS['primary'], labelpad=10)
ax2.set_ylabel('Growth Rate (%)', fontsize=10, color=COLORS['secondary'], labelpad=10)
ax1.set_xlabel('Month', fontsize=10, color=COLORS['text'], labelpad=10)
ax1.yaxis.grid(True, color=COLORS['grid'], linewidth=1)
ax1.set_axisbelow(True)
lines1, labels1 = ax1.get_legend_handles_labels()
lines2, labels2 = ax2.get_legend_handles_labels()
ax1.legend(lines1 + lines2, labels1 + labels2, 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 Scatter Plot examples
☕