Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q4 of 15
Matplotlib - Real-World Visualization Patterns
What will be the output of this code?
import matplotlib.pyplot as plt
fig, axes = plt.subplots(1, 2)
axes[0].plot([1, 2, 3])
axes[1].plot([3, 2, 1])
plt.show()
AOne plot with two lines overlapping
BError because axes is not iterable
CTwo side-by-side line plots: first ascending, second descending
DA single plot with no lines
Step-by-Step Solution
Solution:
  1. Step 1: Understand plt.subplots(1, 2)

    This creates 1 row and 2 columns of plots, so two side-by-side plots.
  2. Step 2: Analyze plotting commands

    axes[0] plots ascending line, axes[1] plots descending line separately.
  3. Final Answer:

    Two side-by-side line plots: first ascending, second descending -> Option C
  4. Quick Check:

    1x2 subplots = two separate plots [OK]
Quick Trick: plt.subplots returns array of axes for multiple plots [OK]
Common Mistakes:
  • Thinking axes is a single plot
  • Assuming overlapping lines
  • Confusing axes indexing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes