Bird
0
0

Given this code:

medium📝 Predict Output Q5 of 15
Matplotlib - Real-World Visualization Patterns
Given this code:
fig, axs = plt.subplots(2, 2)
axs[0, 1].plot([1, 2, 3], [4, 5, 6])
axs[1, 0].bar([1, 2], [3, 4])
plt.tight_layout()

What is the effect of plt.tight_layout() here?
AChanges all plots to line plots
BAdjusts subplot spacing to prevent overlap
CRemoves axis labels
DResizes figure to default size
Step-by-Step Solution
Solution:
  1. Step 1: Understand plt.tight_layout()

    This function automatically adjusts spacing between subplots to avoid label and title overlap.
  2. Step 2: Check other options

    It does not change plot types, remove labels, or resize figure to default.
  3. Final Answer:

    Adjusts subplot spacing to prevent overlap -> Option B
  4. Quick Check:

    tight_layout adjusts spacing = A [OK]
Quick Trick: Use tight_layout() to fix subplot overlaps [OK]
Common Mistakes:
  • Thinking it changes plot types
  • Expecting it removes labels
  • Assuming it resets figure size

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes