Challenge - 5 Problems
Figure and Axes Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this code?
Consider the following code using matplotlib. What will be the type of the variable
ax?Matplotlib
import matplotlib.pyplot as plt fig, ax = plt.subplots() print(type(ax))
Attempts:
2 left
💡 Hint
Remember that plt.subplots() returns a Figure and Axes object.
✗ Incorrect
The plt.subplots() function returns a Figure and an Axes object. The Axes object represents the plot area where data is drawn.
❓ data_output
intermediate2:00remaining
How many Axes are created?
What is the number of Axes objects created by this code?
Matplotlib
import matplotlib.pyplot as plt fig, axs = plt.subplots(2, 2) print(len(axs.flatten()))
Attempts:
2 left
💡 Hint
The argument (2, 2) creates a grid of subplots.
✗ Incorrect
plt.subplots(2, 2) creates a 2x2 grid of Axes, so there are 4 Axes objects.
🔧 Debug
advanced2:00remaining
Identify the error in this code
What error will this code raise when run?
Matplotlib
import matplotlib.pyplot as plt fig = plt.figure() ax1, ax2 = fig.add_subplot(121) ax3 = fig.add_subplot(122) print(type(ax1))
Attempts:
2 left
💡 Hint
Check the return value of add_subplot when called with a single argument.
✗ Incorrect
fig.add_subplot(121) returns a single Axes object, so trying to unpack it into two variables causes a ValueError.
❓ visualization
advanced2:00remaining
What does this plot look like?
Given this code, what is the layout of the subplots?
Matplotlib
import matplotlib.pyplot as plt fig, axs = plt.subplots(1, 3) for i, ax in enumerate(axs): ax.plot([0, 1], [i, i+1]) plt.show()
Attempts:
2 left
💡 Hint
The arguments (1, 3) create a grid with 1 row and 3 columns.
✗ Incorrect
plt.subplots(1, 3) creates 3 Axes arranged horizontally in one row.
🧠 Conceptual
expert3:00remaining
Understanding Figure and Axes relationship
Which statement correctly describes the relationship between Figure and Axes in matplotlib?
Attempts:
2 left
💡 Hint
Think about how plots are organized inside a figure.
✗ Incorrect
A Figure is the overall window or page, and it can hold many Axes (plots). Each Axes is part of one Figure only.