Bird
0
0

What will this code display?

medium📝 Predict Output Q5 of 15
Matplotlib - Seaborn Integration
What will this code display?
import seaborn as sns
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
sns.barplot(x=['A','B'], y=[10, 20], ax=ax)
ax.set_xlabel('Category')
ax.set_ylabel('Value')
plt.show()
AA bar plot with labeled x-axis 'Category' and y-axis 'Value'
BA bar plot without axis labels
CAn error because ax.set_xlabel() cannot be used with Seaborn
DA blank figure with axis labels only
Step-by-Step Solution
Solution:
  1. Step 1: Understand plot and axis usage

    Seaborn draws barplot on Matplotlib axis ax, which allows axis label customization.
  2. Step 2: Confirm axis labels are set and plot shown

    ax.set_xlabel() and ax.set_ylabel() add labels, plt.show() displays the plot.
  3. Final Answer:

    A bar plot with labeled x-axis 'Category' and y-axis 'Value' -> Option A
  4. Quick Check:

    Seaborn plot on ax + ax labels = labeled plot [OK]
Quick Trick: Use ax parameter to customize Seaborn plots with Matplotlib [OK]
Common Mistakes:
  • Believing axis labels won't show
  • Thinking ax.set_xlabel() causes error
  • Expecting blank plot

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes