Bird
0
0

Find the mistake in this dashboard layout code:

medium📝 Debug Q7 of 15
Matplotlib - Real-World Visualization Patterns
Find the mistake in this dashboard layout code:
fig, axs = plt.subplots(1, 3)
for i in range(4):
    axs[i].plot([1, 2, 3], [3, 2, 1])
ATypeError because axs is not iterable
BSyntaxError due to missing colon
CNo mistake, code runs correctly
DIndexError because axs has only 3 elements but loop runs 4 times
Step-by-Step Solution
Solution:
  1. Step 1: Check axs length

    plt.subplots(1, 3) creates 3 subplots, so axs has length 3 with indices 0,1,2.
  2. Step 2: Analyze loop range

    The loop runs from 0 to 3 (4 times), so axs[3] access causes IndexError.
  3. Final Answer:

    IndexError because axs has only 3 elements but loop runs 4 times -> Option D
  4. Quick Check:

    Loop index exceeds axs size = C [OK]
Quick Trick: Loop indices must match subplot count [OK]
Common Mistakes:
  • Ignoring zero-based indexing
  • Confusing syntax errors with index errors
  • Assuming axs is iterable but longer

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes