The file is saved as 'output.pdf', which is a vector format.
Step 2: Understand matplotlib output choice
Matplotlib chooses vector output for .pdf files automatically.
Final Answer:
Vector image file -> Option C
Quick Check:
PDF extension = Vector output [OK]
Hint: File extension determines vector or raster output [OK]
Common Mistakes:
Assuming .pdf is raster
Thinking no file is saved
Confusing output type with plot type
4. You want to save a detailed photo using matplotlib but accidentally use plt.savefig('photo.svg'). What is the main problem with this?
medium
A. SVG is a vector format and may not handle photo details well
B. SVG files are always corrupted
C. Matplotlib will save a raster image inside SVG
D. No file will be saved
Solution
Step 1: Understand SVG format
SVG is vector-based, best for shapes and lines, not detailed photos.
Step 2: Recognize photo detail needs
Photos have many colors and pixels; vector formats can't represent them well.
Final Answer:
SVG is a vector format and may not handle photo details well -> Option A
Quick Check:
Photo detail needs raster, SVG is vector [OK]
Hint: Use raster formats for photos, not vector like SVG [OK]
Common Mistakes:
Thinking SVG files are corrupted
Expecting raster inside SVG
Assuming no file is saved
5. You have a matplotlib plot with both a detailed photo background and vector line plots on top. Which approach best preserves quality when saving the figure?
hard
A. Save as a raster image like .png to capture photo details
B. Save as a vector image like .pdf to keep lines sharp
C. Save two separate files: photo as raster and lines as vector
D. Save as .svg and expect both photo and lines to be perfect
Solution
Step 1: Analyze image components
The photo background needs raster to keep details; vector lines alone won't capture photo well.
Step 2: Choose output that preserves all parts
Saving as raster (.png) keeps photo details and acceptable line quality.
Step 3: Consider alternatives
Saving separate files is complex; .svg won't handle photo well.
Final Answer:
Save as a raster image like .png to capture photo details -> Option A
Quick Check:
Photo + lines = raster output best [OK]
Hint: For photos with lines, raster (.png) keeps all details [OK]