Raster vs vector formats for saving Matplotlib figures: when to use SVG or PDF versus PNG or JPEG

Quick Overview

Asks how raster and vector image formats differ when saving Matplotlib figures and when to pick SVG or PDF over PNG or JPEG. Tests practical plotting judgment about resolution, file size for dense data, print quality and mixing both kinds in one figure.

Raster vs vector formats for saving Matplotlib figures: when to use SVG or PDF versus PNG or JPEG

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Other

Describe the difference between raster and vector graphics when saving Matplotlib figures. When would you choose a vector format like `SVG` or `PDF` versus a raster format like `PNG` or `JPEG`? ```hint Grow the data Think about how the file size of each format changes when a scatter plot goes from 100 points to 1,000,000 points. ``` ```hint Look at the edges Zoom into the axis labels and thin lines of a saved chart in each format. Ask what the file actually stores at that spot. ``` ### What a Strong Answer Covers - How each kind of format stores a figure, and what that means for zooming and printing - How file size and rendering speed scale with data density in each kind - The difference between lossless and lossy raster formats for charts - Concrete situations that call for each kind, and a way to combine them in one figure - Matplotlib settings that change the output, such as resolution or how text is written ### Follow-up Questions - A PDF with a million-point scatter takes ten seconds to open. How do you fix it without losing crisp axis labels? - Your PNG looks blurry on a printed poster. What do you change in `savefig`? - A journal asks for figures with editable text. What do you set in Matplotlib? - Why does a JPEG of a line chart look worse than a PNG of similar file size?

Overview: Asks how raster and vector image formats differ when saving Matplotlib figures and when to pick SVG or PDF over PNG or JPEG. Tests practical plotting judgment about resolution, file size for dense data, print quality and mixing both kinds in one figure.

PracHub logo
General
Nov 25, 2026
mediumData ScientistOtherData Manipulation (SQL/Python)
0
0

Describe the difference between raster and vector graphics when saving Matplotlib figures. When would you choose a vector format like SVG or PDF versus a raster format like PNG or JPEG?

What a Strong Answer Covers Guidance

  • How each kind of format stores a figure, and what that means for zooming and printing
  • How file size and rendering speed scale with data density in each kind
  • The difference between lossless and lossy raster formats for charts
  • Concrete situations that call for each kind, and a way to combine them in one figure
  • Matplotlib settings that change the output, such as resolution or how text is written

Follow-up Questions Guidance

  • A PDF with a million-point scatter takes ten seconds to open. How do you fix it without losing crisp axis labels?
  • Your PNG looks blurry on a printed poster. What do you change in savefig ?
  • A journal asks for figures with editable text. What do you set in Matplotlib?
  • Why does a JPEG of a line chart look worse than a PNG of similar file size?