B. tight_layout() must be called before subplots()
C. The parameter name should be 'pad' not 'padding'
D. plt.show() should be called before tight_layout()
Solution
Step 1: Check parameter names for tight_layout()
The correct parameter to control padding is pad, not padding.
Step 2: Confirm function call order
tight_layout() should be called after creating subplots and before plt.show(), which is correct here.
Final Answer:
The parameter name should be 'pad' not 'padding' -> Option C
Quick Check:
Use pad= not padding= [OK]
Hint: Use 'pad' parameter, not 'padding' [OK]
Common Mistakes:
Using wrong parameter names
Calling tight_layout before creating subplots
Calling plt.show() before tight_layout
5. You have a figure with 3 subplots and long axis labels causing overlap. How can you use tight_layout() to fix this and add extra space on the right side for a legend?
hard
A. Call plt.tight_layout(pad=0) to remove all padding
B. Call plt.tight_layout(rect=[0, 0, 0.85, 1]) to leave space on the right
C. Call plt.tight_layout(w_pad=5, h_pad=5) to increase padding equally
D. Call plt.tight_layout() without parameters; it always reserves legend space
Solution
Step 1: Understand the rect parameter
The rect parameter defines the area for subplots as [left, bottom, right, top] in normalized figure coordinates.
Step 2: Use rect to leave space for legend
Setting rect=[0, 0, 0.85, 1] shrinks subplot area to 85% width, leaving right space for legend.
Final Answer:
Call plt.tight_layout(rect=[0, 0, 0.85, 1]) to leave space on the right -> Option B
Quick Check:
rect shrinks plot area for legend space [OK]
Hint: Use rect to reserve space for legends [OK]
Common Mistakes:
Setting pad=0 removes needed spacing
Assuming tight_layout reserves legend space automatically
Using only w_pad and h_pad without adjusting rect
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.