Bird
0
0

Identify the error in this code that tries to set figure size:

medium📝 Debug Q14 of 15
Matplotlib - Export and Publication Quality
Identify the error in this code that tries to set figure size:
import matplotlib.pyplot as plt
plt.figure(figsize=8, 4)
plt.plot([1, 2], [3, 4])
plt.show()
ANo error, code runs fine
Bplt.plot syntax is incorrect
Cfigsize should be a tuple, not two separate arguments
Dplt.show() is missing parentheses
Step-by-Step Solution
Solution:
  1. Step 1: Check figsize parameter usage

    The code uses figsize=8, 4 which passes two separate arguments instead of a single tuple.
  2. Step 2: Understand correct figsize syntax

    Correct syntax requires a tuple: figsize=(8, 4). Without parentheses, it causes a TypeError.
  3. Final Answer:

    figsize should be a tuple, not two separate arguments -> Option C
  4. Quick Check:

    figsize=(width, height) needs parentheses [OK]
Quick Trick: Always use parentheses for figsize tuple [OK]
Common Mistakes:
  • Passing figsize values without parentheses
  • Confusing plt.plot syntax errors
  • Forgetting plt.show() parentheses (not the case here)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes