Bird
0
0

What will the following code output?

medium📝 Predict Output Q13 of 15
Matplotlib - Seaborn Integration
What will the following code output?
import seaborn as sns
import matplotlib.pyplot as plt

df = sns.load_dataset('tips')
fig, ax = plt.subplots()
sns.scatterplot(data=df, x='total_bill', y='tip', ax=ax)
plt.title('Scatterplot on existing axes')
plt.show()
AA scatterplot of total_bill vs tip on a new figure with default title
BAn empty plot with no points
CA scatterplot of total_bill vs tip on the existing axes with custom title
DAn error because scatterplot cannot accept ax parameter
Step-by-Step Solution
Solution:
  1. Step 1: Analyze code creating figure and axes

    The code creates a figure and axes with plt.subplots() and stores axes in ax.
  2. Step 2: Understand scatterplot with ax parameter

    scatterplot is axes-level and plots on the given ax. Title is set on the figure.
  3. Final Answer:

    A scatterplot of total_bill vs tip on the existing axes with custom title -> Option C
  4. Quick Check:

    Axes-level plot on existing axes = scatterplot with ax= [OK]
Quick Trick: Axes-level plots use ax= to draw on existing axes [OK]
Common Mistakes:
  • Expecting scatterplot to create new figure automatically
  • Thinking ax= causes error with scatterplot
  • Assuming title applies only to figure-level plots

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes