Bird
0
0

What will be the output layout when running this code?

medium📝 Predict Output Q13 of 15
Matplotlib - Real-World Visualization Patterns
What will be the output layout when running this code?
fig, axs = plt.subplots(1, 3)
for ax in axs:
    ax.plot([1, 2, 3], [1, 4, 9])
plt.tight_layout()
plt.show()
AThree rows with one chart each stacked vertically
BA single row with three side-by-side line charts
COne chart only with three lines overlapping
DAn error because plt.tight_layout() is missing parameters
Step-by-Step Solution
Solution:
  1. Step 1: Analyze plt.subplots(1, 3)

    This creates 1 row and 3 columns, so three charts side by side.
  2. Step 2: Understand the loop plotting

    Each axis plots the same line chart, so three separate charts appear horizontally.
  3. Final Answer:

    A single row with three side-by-side line charts -> Option B
  4. Quick Check:

    1 row, 3 cols = 3 charts side by side [OK]
Quick Trick: Rows x cols in plt.subplots defines chart grid shape [OK]
Common Mistakes:
  • Thinking 1,3 means 3 rows stacked vertically
  • Assuming all lines plot on one chart
  • Believing plt.tight_layout() causes errors without args

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes