0
0
Matplotlibdata~20 mins

Vector vs raster output decision in Matplotlib - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Vector vs Raster Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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')
AA plain text file with raw data points
BA vector image file (paths and shapes) like SVG
CA raster image file (pixels) like PNG or JPEG
DA binary executable file
Attempts:
2 left
💡 Hint
SVG files store images as shapes and lines, not pixels.
Predict Output
intermediate
2: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)
AThe low_res.png will have more pixels than high_res.png
BBoth files will have the same pixel dimensions and quality
CThe high_res.png will have more pixels and better detail than low_res.png
DThe dpi setting only affects vector files, not PNG
Attempts:
2 left
💡 Hint
DPI means dots per inch, affecting pixel density in raster images.
data_output
advanced
2: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')
AThe PNG file is usually smaller than the SVG for complex plots
BFile size depends only on image resolution, not format
CBoth files have the same size regardless of plot complexity
DThe SVG file is usually smaller than the PNG for complex plots
Attempts:
2 left
💡 Hint
Vector files store instructions for shapes, which can grow with complexity.
🧠 Conceptual
advanced
2: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?
AVector formats like PDF or SVG
BRaster formats like PNG or JPEG
CPlain text files with raw data
DBitmap formats like BMP
Attempts:
2 left
💡 Hint
Think about scaling images without pixelation.
🔧 Debug
expert
2: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)
AThe dpi setting only affects screen display, not saved files
BPNG format is vector and does not support dpi settings
CThe plot data is incorrect causing blurriness
DThe dpi is too low, resulting in fewer pixels and less detail
Attempts:
2 left
💡 Hint
DPI controls pixel density in raster images.