Challenge - 5 Problems
Vector vs Raster Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output format of matplotlib savefig with vector format
What type of file is produced by this code snippet?
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.savefig('output.svg')Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.savefig('output.svg')
Attempts:
2 left
💡 Hint
SVG files store images as shapes and lines, not pixels.
✗ Incorrect
Saving as 'output.svg' produces a vector image file. Vector files store shapes and lines, so they scale without losing quality.
❓ Predict Output
intermediate2:00remaining
Effect of dpi on raster output in matplotlib
What happens when you save a plot as a PNG with dpi=300 compared to dpi=72?
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.savefig('high_res.png', dpi=300)
plt.savefig('low_res.png', dpi=72)Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.savefig('high_res.png', dpi=300) plt.savefig('low_res.png', dpi=72)
Attempts:
2 left
💡 Hint
DPI means dots per inch, affecting pixel density in raster images.
✗ Incorrect
Higher dpi means more pixels per inch, so the image is sharper and larger in pixel dimensions.
❓ data_output
advanced2:00remaining
Comparing file sizes of vector vs raster outputs
Given a plot saved as 'plot.svg' (vector) and 'plot.png' (raster), which statement about their file sizes is generally true for complex plots?
Matplotlib
import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 10, 1000) y = np.sin(x) plt.plot(x, y) plt.savefig('plot.svg') plt.savefig('plot.png')
Attempts:
2 left
💡 Hint
Vector files store instructions for shapes, which can grow with complexity.
✗ Incorrect
For complex plots with many points, vector files can become very large because they store every shape and line, while raster files store pixels and can be compressed.
🧠 Conceptual
advanced2:00remaining
Choosing output format for publication-quality figures
Which output format is best for figures that need to be scaled to any size without losing quality in a scientific paper?
Attempts:
2 left
💡 Hint
Think about scaling images without pixelation.
✗ Incorrect
Vector formats store shapes and lines mathematically, so they scale perfectly without losing quality, ideal for publication.
🔧 Debug
expert2:00remaining
Why does saving a plot as PNG with dpi=100 produce a blurry image?
A user saves a matplotlib plot as PNG with dpi=100 but the image looks blurry when zoomed in. Which option explains the cause?
Matplotlib
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.savefig('blurry.png', dpi=100)
Attempts:
2 left
💡 Hint
DPI controls pixel density in raster images.
✗ Incorrect
Low dpi means fewer pixels per inch, so the image looks blurry when zoomed or printed large.