Bird
0
0

What output does this code produce?

medium📝 Predict Output Q5 of 15
Matplotlib - Real-World Visualization Patterns
What output does this code produce?
import matplotlib.pyplot as plt
fig, axs = plt.subplots(2)
axs[0].plot([1, 2], [3, 4])
axs[1].bar([1, 2], [5, 6])
plt.show()
AA single plot with both line and bar charts overlapped
BTwo plots stacked vertically: a line plot on top and a bar chart below
CAn error because plt.subplots needs 2 arguments
DTwo plots side by side horizontally
Step-by-Step Solution
Solution:
  1. Step 1: Understand plt.subplots(2)

    This creates 2 subplots stacked vertically by default.
  2. Step 2: Analyze plotting commands

    axs[0] gets a line plot, axs[1] gets a bar chart.
  3. Final Answer:

    Two plots stacked vertically: a line plot on top and a bar chart below -> Option B
  4. Quick Check:

    plt.subplots(2) stacks plots vertically [OK]
Quick Trick: plt.subplots(n) stacks n plots vertically by default [OK]
Common Mistakes:
  • Expecting horizontal layout
  • Thinking plots overlap

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes