Recall & Review
beginner
What does the
plt.subplots() function return in matplotlib?It returns two objects:
fig, which is the Figure object representing the entire window or page, and ax, which is the Axes object where the actual plot is drawn.Click to reveal answer
beginner
Why do we use
fig, ax = plt.subplots() instead of just plt.plot()?Using
fig, ax = plt.subplots() gives more control over the plot. You can customize the figure size, add multiple plots, and modify axes properties easily.Click to reveal answer
intermediate
How can you create multiple plots in one figure using
plt.subplots()?You can pass the number of rows and columns as arguments, like
fig, axs = plt.subplots(2, 2). This creates a grid of 4 plots, and axs is an array of Axes objects.Click to reveal answer
beginner
What is the role of the
fig object in the fig, ax = plt.subplots() pattern?The
fig object represents the whole figure or window. You can use it to set the figure size, save the figure to a file, or adjust layout settings.Click to reveal answer
beginner
How do you plot data on the axes object returned by
plt.subplots()?You call plotting methods on the
ax object, like ax.plot(x, y). This draws the plot inside the axes area of the figure.Click to reveal answer
What does
ax represent in fig, ax = plt.subplots()?✗ Incorrect
ax is the axes object where the plot is drawn, not the whole figure.
How do you create a 3x1 grid of plots using
plt.subplots()?✗ Incorrect
Passing rows=3 and columns=1 creates a vertical stack of 3 plots.
Which object do you use to save the plot to a file?
✗ Incorrect
The fig object has the savefig() method to save the figure.
What is the default number of plots created by
plt.subplots() with no arguments?✗ Incorrect
By default, it creates one figure and one axes (one plot).
How do you plot a line graph on the axes object?
✗ Incorrect
You use ax.plot(x, y) to plot on the specific axes.
Explain the purpose of the
fig and ax objects returned by plt.subplots().Think about the difference between the whole window and the area where you draw.
You got /4 concepts.
Describe how to create multiple plots in one figure using
plt.subplots() and how to access each plot.Consider a grid of small plots inside one big window.
You got /4 concepts.