Bird
0
0

Find the mistake in this code snippet:

medium📝 Debug Q7 of 15
Matplotlib - Seaborn Integration
Find the mistake in this code snippet:
import seaborn as sns
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
sns.histplot(data=[1,2,3,4], ax=plt)
ax.set_title('Histogram')
plt.show()
Asns.histplot does not accept ax parameter
Bax.set_title() should be plt.set_title()
Cax parameter should be ax, not plt
Dplt.show() should be called before ax.set_title()
Step-by-Step Solution
Solution:
  1. Step 1: Check ax parameter usage

    sns.histplot expects ax to be an axis object, but plt (module) is passed incorrectly.
  2. Step 2: Correct ax parameter

    Passing ax (the axis object) fixes the error.
  3. Final Answer:

    ax parameter should be ax, not plt -> Option C
  4. Quick Check:

    ax param = axis object, not plt module [OK]
Quick Trick: Pass axis object, not plt module, to ax parameter [OK]
Common Mistakes:
  • Passing plt instead of ax to ax parameter
  • Confusing set_title() usage
  • Calling plt.show() before setting title

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes