A figure has a physical size (in inches) and a resolution (dots per inch). Together they set the pixel dimensions and how text and lines scale — crucial for matching a chart to its destination.
Size and DPI
fig, ax = plt.subplots(figsize=(8, 5), dpi=100)# → 800 × 500 pixels on screenfig.savefig("chart.png", dpi=300) # → 2400 × 1500 px for print
Key takeaways
- 01figsize=(w, h) sets the physical size in inches; dpi sets dots per inch.
- 02Pixel dimensions = figsize × dpi.
- 03Pick figsize for the aspect ratio and space; raise dpi (e.g. 300) at save time for print.
- 04Bigger figsize makes text relatively smaller; higher dpi just adds pixels.
