Page2/13
Line Charts & Anatomy of a Plot · Page 2 of 2
Subplots & Multi-Panel Figures
Subplots — Multiple Panels in One Figure
Use plt.subplots(rows, cols) to create grid layouts:
fig, axes = plt.subplots(2, 2, figsize=(12, 8))
ax1, ax2 = axes[0] # top row
ax3, ax4 = axes[1] # bottom row
Sharing Axes
# Share y-axis for comparison
fig, (ax1, ax2) = plt.subplots(1, 2, sharey=True)
plt.tight_layout()
Always call this before saving — it automatically adjusts spacing so labels don't overlap.
Common Line Styles
| Style | Code |
|---|---|
| Solid | '-' |
| Dashed | '--' |
| Dotted | ':' |
| Dash-dot | '-.' |
Common Markers
'o' circle, 's' square, '^' triangle, 'D' diamond, '*' star
main.py
Loading...
OUTPUT
▶Click "Run Code" to execute…