Challenge - 5 Problems
Facet Grid Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of a simple facet grid plot
What will be the shape of the figure created by this code using matplotlib's subplots for small multiples?
Matplotlib
import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 10, 100) fig, axs = plt.subplots(2, 3) for i, ax in enumerate(axs.flatten()): ax.plot(x, np.sin(x + i)) plt.close(fig) print(fig.get_size_inches())
Attempts:
2 left
💡 Hint
The default figsize for plt.subplots is (6, 4) inches.
✗ Incorrect
By default, plt.subplots creates a figure of size 6 inches wide and 4 inches tall unless specified otherwise.
❓ data_output
intermediate1:30remaining
Number of subplots created
How many subplots will be created by this code snippet?
Matplotlib
import matplotlib.pyplot as plt fig, axs = plt.subplots(3, 4) print(len(axs.flatten()))
Attempts:
2 left
💡 Hint
Count rows times columns.
✗ Incorrect
3 rows times 4 columns equals 12 subplots.
❓ visualization
advanced2:00remaining
Identify the correct facet grid layout
Which option shows the correct arrangement of subplots for this code?
Matplotlib
import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 2 * np.pi, 100) fig, axs = plt.subplots(2, 2) for i, ax in enumerate(axs.flatten()): ax.plot(x, np.sin(x + i)) plt.close(fig) # The question is about the layout of subplots in a 2x2 grid.
Attempts:
2 left
💡 Hint
Check the arguments of plt.subplots(2, 2).
✗ Incorrect
plt.subplots(2, 2) creates a grid with 2 rows and 2 columns, so 4 plots arranged accordingly.
🔧 Debug
advanced1:30remaining
Error in facet grid subplot indexing
What error will this code raise?
Matplotlib
import matplotlib.pyplot as plt fig, axs = plt.subplots(2, 2) axs[2].plot([1, 2, 3], [4, 5, 6])
Attempts:
2 left
💡 Hint
axs is a 2D array of shape (2, 2).
✗ Incorrect
axs is a 2x2 array, so axs[2] is out of bounds. Indexing must be two-dimensional or flattened first.
🚀 Application
expert2:30remaining
Creating a facet grid with shared axes
Which code snippet correctly creates a 3x2 facet grid with shared x and y axes using matplotlib?
Attempts:
2 left
💡 Hint
Check the order of rows and columns and the sharex/sharey parameters.
✗ Incorrect
plt.subplots(3, 2, sharex=True, sharey=True) creates 3 rows and 2 columns with shared axes.