Python Matplotlib Visualization Quiz
A 35-question quiz covering Matplotlib figure structure, axes elements, line charts, labels, legends, and exporting plots.
Question 1
What is the top-level container for all plot elements in Matplotlib?
Question 2
Which command creates a new Figure and a single set of Axes using the object-oriented approach?
import matplotlib.pyplot as plt
# Create figure and axes
Question 3
What is the relationship between a Figure and an Axes?
Question 4
How do you create a Figure with a grid of 2 rows and 3 columns of subplots?
fig, axes = plt.subplots(____, ____)
Question 5
What does `plt.show()` do?
Question 6
If you have `fig, axes = plt.subplots(2, 2)`, what is the data type of `axes`?
Question 7
Which method sets the range (limits) of the x-axis?
Question 8
How do you turn on the grid lines for a specific plot `ax`?
fig, ax = plt.subplots()
ax.plot([1, 2, 3])
# Turn on grid
Question 9
What are 'spines' in Matplotlib?
Question 10
How would you remove the top and right spines from a plot `ax`?
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
Question 11
What is the difference between `ax.set_xticks()` and `ax.set_xticklabels()`?
Question 12
How do you set a logarithmic scale for the y-axis?
Question 13
Which method is used to draw a basic line chart?
Question 14
How do you create a red dashed line with circle markers?
ax.plot(x, y, ____)
Question 15
You have two arrays `x` and `y`. How do you plot them?
Question 16
How do you change the line width to be thicker?
ax.plot(x, y, linewidth=____)
Question 17
What happens if you call `ax.plot()` multiple times on the same Axes?
Question 18
How do you plot a line that is just markers (no connecting lines)?
Question 19
Which method sets the main title of the Axes?
Question 20
How do you label the x and y axes?
ax.set_xlabel('Time')
ax.set_ylabel('Velocity')
Question 21
You want to add a text annotation at a specific coordinate (x=2, y=5). Which command do you use?
Question 22
How can you change the font size of the title?
Question 23
What is a 'suptitle'?
Question 24
How do you support mathematical expressions (LaTeX) in labels?
ax.set_xlabel(r'$E = mc^2$')
Question 25
To display a legend, what must you provide when plotting data?
ax.plot(x, y, label='My Data')
ax.legend()
Question 26
How do you place the legend in the 'upper right' corner?
Question 27
Can you create a legend without setting labels in `plot()`?
line1, = ax.plot(x, y1)
line2, = ax.plot(x, y2)
ax.legend([line1, line2], ['Label 1', 'Label 2'])
Question 28
How do you remove the frame (box) around the legend?
Question 29
What does `bbox_to_anchor` do in `legend()`?
Question 30
If you have multiple subplots, how do you create a single legend for the whole figure?
Question 31
Which method saves the current figure to a file?
Question 32
How do you save a plot with a transparent background?
Question 33
What does the `dpi` parameter control in `savefig()`?
Question 34
Why might labels be cut off when saving a figure, and how do you fix it?
Question 35
Which file format is vector-based (infinite resolution)?
