Bird
0
0

Identify the error in the code below that tries to change the figure size of a Seaborn plot:

medium📝 Debug Q14 of 15
Matplotlib - Seaborn Integration
Identify the error in the code below that tries to change the figure size of a Seaborn plot:
import seaborn as sns
import matplotlib.pyplot as plt

sns_plot = sns.barplot(x=[1,2,3], y=[4,5,6])
sns_plot.figure(figsize=(10,5))
plt.show()
AThe correct method is sns_plot.set_figsize(10,5)
BThe figure size should be set using plt.figure(figsize=(10,5)) before plotting
Csns.barplot does not support figure size changes
DFigure size cannot be changed after plotting
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to set figure size in Matplotlib

    Figure size is set by creating a figure with plt.figure(figsize=(width,height)) before plotting.
  2. Step 2: Identify the mistake in the code

    Calling sns_plot.figure(figsize=(10,5)) is incorrect because 'figure' is not a method of the plot object.
  3. Final Answer:

    The figure size should be set using plt.figure(figsize=(10,5)) before plotting -> Option B
  4. Quick Check:

    Set figure size with plt.figure() before plotting [OK]
Quick Trick: Use plt.figure(figsize=...) before plotting [OK]
Common Mistakes:
  • Calling figure() on plot object
  • Trying to set figure size after plot creation
  • Using non-existent set_figsize method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes