Challenge - 5 Problems
Figure Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the size of the figure created?
Consider the following code snippet using matplotlib:
What will be the output of this code?
import matplotlib.pyplot as plt fig = plt.figure(figsize=(8, 4)) print(fig.get_size_inches())
What will be the output of this code?
Matplotlib
import matplotlib.pyplot as plt fig = plt.figure(figsize=(8, 4)) print(fig.get_size_inches())
Attempts:
2 left
💡 Hint
The figsize parameter sets the width and height in inches.
✗ Incorrect
The figsize argument in plt.figure sets the width and height of the figure in inches. The get_size_inches() method returns these dimensions as a numpy array.
❓ data_output
intermediate2:00remaining
How many axes are in the figure?
Given this code:
What is the printed output?
import matplotlib.pyplot as plt fig = plt.figure() ax1 = fig.add_subplot(121) ax2 = fig.add_subplot(122) print(len(fig.axes))
What is the printed output?
Matplotlib
import matplotlib.pyplot as plt fig = plt.figure() ax1 = fig.add_subplot(121) ax2 = fig.add_subplot(122) print(len(fig.axes))
Attempts:
2 left
💡 Hint
Each add_subplot call adds one axes to the figure.
✗ Incorrect
The figure has two subplots added, so fig.axes contains two Axes objects.
❓ visualization
advanced2:30remaining
What does the figure look like?
Examine this code:
Which description best matches the figure displayed?
import matplotlib.pyplot as plt fig = plt.figure(figsize=(6, 3)) ax = fig.add_axes([0.1, 0.1, 0.8, 0.8]) ax.plot([1, 2, 3], [4, 5, 6]) plt.show()
Which description best matches the figure displayed?
Matplotlib
import matplotlib.pyplot as plt fig = plt.figure(figsize=(6, 3)) ax = fig.add_axes([0.1, 0.1, 0.8, 0.8]) ax.plot([1, 2, 3], [4, 5, 6]) plt.show()
Attempts:
2 left
💡 Hint
figsize sets width and height; add_axes controls plot position and size.
✗ Incorrect
The figure is 6 inches wide and 3 inches tall, making it wide and short. The axes fill 80% width and height starting at 10% from left and bottom, so the plot fills most of the figure.
🔧 Debug
advanced2:00remaining
Why does this code raise an error?
Look at this code:
Why does it raise an error?
import matplotlib.pyplot as plt fig = plt.figure(figsize=8, 4) ax = fig.add_subplot(111) plt.show()
Why does it raise an error?
Matplotlib
import matplotlib.pyplot as plt fig = plt.figure(figsize=8, 4) ax = fig.add_subplot(111) plt.show()
Attempts:
2 left
💡 Hint
Check the syntax of figsize parameter.
✗ Incorrect
figsize expects a single tuple argument like (8, 4). Passing two separate arguments causes a TypeError.
🚀 Application
expert3:00remaining
How to create two figures with different sizes?
You want to create two separate figures with sizes 5x5 and 10x2 inches respectively. Which code correctly creates these figures and prints their sizes?
Matplotlib
import matplotlib.pyplot as plt fig1 = plt.figure(figsize=(5, 5)) fig2 = plt.figure(figsize=(10, 2)) print(fig1.get_size_inches()) print(fig2.get_size_inches())
Attempts:
2 left
💡 Hint
figsize must be a tuple of two numbers.
✗ Incorrect
Only option B correctly passes figsize as tuples. Option B passes separate arguments causing error. Option B uses list instead of tuple (works but not recommended). Option B passes single values creating square figures.