Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q14 of 15
Matplotlib - Seaborn Integration
Identify the error in this code snippet:
import seaborn as sns
import matplotlib.pyplot as plt

sns.set_style('whitegrid')
plt.bar([1, 2, 3], [4, 5])
plt.show()
Aplt.show() is missing parentheses.
Bsns.set_style('whitegrid') is not a valid style.
CThe lengths of x and y data lists do not match.
Dplt.bar cannot be used with seaborn styles.
Step-by-Step Solution
Solution:
  1. Step 1: Check sns.set_style usage

    'whitegrid' is a valid style in Seaborn, so no error here.
  2. Step 2: Check plt.bar arguments

    plt.bar requires x and y lists of the same length; here x has 3 items, y has 2, causing an error.
  3. Final Answer:

    The lengths of x and y data lists do not match. -> Option C
  4. Quick Check:

    Mismatch in bar plot data lengths = D [OK]
Quick Trick: Bar plot x and y must have same length [OK]
Common Mistakes:
  • Assuming sns.set_style causes error
  • Thinking plt.show needs no parentheses
  • Believing seaborn styles restrict Matplotlib functions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes