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:
Step 1: Identify the correct Matplotlib function
To add a vertical line, plt.axvline() is used.
Step 2: Check parameters
plt.axvline(x=2, color='red') adds a vertical red line at x=2.
Step 3: Verify other options
plt.axhline adds horizontal line; plt.axline and plt.vline do not exist or are incorrect.
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.
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
Master "Seaborn Integration" in Matplotlib
9 interactive learning modes - each teaches the same concept differently