Bird
0
0

Examine the code below and identify the issue:

medium📝 Debug Q6 of 15
Matplotlib - Real-World Visualization Patterns
Examine the code below and identify the issue:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3], [4, 5])
plt.show()
AThe <code>plt.subplots()</code> function is called incorrectly
BThe x and y data lists have different lengths
CThe <code>plt.show()</code> command is missing
DThe <code>ax.plot()</code> method does not exist
Step-by-Step Solution
Solution:
  1. Step 1: Check data lengths

    The x data has 3 points, y data has 2 points.
  2. Step 2: Understand plotting requirements

    Plotting requires x and y arrays to be the same length.
  3. Final Answer:

    The x and y data lists have different lengths -> Option B
  4. Quick Check:

    Data length mismatch causes error [OK]
Quick Trick: Ensure x and y data lengths match [OK]
Common Mistakes:
  • Ignoring length mismatch between x and y
  • Assuming plt.subplots() usage is incorrect
  • Thinking plt.show() is missing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes