Bird
0
0

You have created a Seaborn violin plot and want to add a vertical line at x=2 using Matplotlib. Which code snippet correctly achieves this?

hard📝 Application Q8 of 15
Matplotlib - Seaborn Integration
You have created a Seaborn violin plot and want to add a vertical line at x=2 using Matplotlib. Which code snippet correctly achieves this?
Aimport matplotlib.pyplot as plt import seaborn as sns sns.violinplot(data=[1,2,3,4,5]) plt.axvline(x=2, color='red') plt.show()
Bimport matplotlib.pyplot as plt import seaborn as sns sns.violinplot(data=[1,2,3,4,5]) plt.axhline(y=2, color='red') plt.show()
Cimport matplotlib.pyplot as plt import seaborn as sns sns.violinplot(data=[1,2,3,4,5]) plt.axline(x=2, color='red') plt.show()
Dimport matplotlib.pyplot as plt import seaborn as sns sns.violinplot(data=[1,2,3,4,5]) plt.vline(x=2, color='red') plt.show()
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct Matplotlib function

    To add a vertical line, plt.axvline() is used.
  2. Step 2: Check parameters

    plt.axvline(x=2, color='red') adds a vertical red line at x=2.
  3. Step 3: Verify other options

    plt.axhline adds horizontal line; plt.axline and plt.vline do not exist or are incorrect.
  4. Final Answer:

    import matplotlib.pyplot as plt import seaborn as sns sns.violinplot(data=[1,2,3,4,5]) plt.axvline(x=2, color='red') plt.show() correctly adds a vertical line at x=2.
  5. Quick Check:

    Vertical line = plt.axvline [OK]
Quick Trick: Use plt.axvline for vertical lines, plt.axhline for horizontal [OK]
Common Mistakes:
  • Using plt.axhline instead of plt.axvline for vertical lines
  • Using non-existent plt.vline or plt.axline functions
  • Not specifying the x parameter correctly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes