What will be the color of the line plotted by Matplotlib after the Seaborn scatter plot?
import matplotlib.pyplot as plt import seaborn as sns sns.set_style('darkgrid') plt.scatter([1, 2, 3], [4, 5, 6], color='red') plt.plot([1, 2, 3], [6, 5, 4]) plt.show()
Seaborn sets styles but does not change Matplotlib's default line color unless specified.
Seaborn's set_style changes the background grid style but does not affect the default line color of Matplotlib plots. The scatter points are red because explicitly set, but the line uses Matplotlib's default blue color.
What is the number of lines plotted after running this code?
import matplotlib.pyplot as plt import seaborn as sns import pandas as pd df = pd.DataFrame({'x': [1, 2, 3], 'y': [3, 2, 1]}) sns.lineplot(data=df, x='x', y='y') plt.plot([1, 2, 3], [1, 2, 3]) lines = plt.gca().get_lines() print(len(lines))
Count all lines added by both Seaborn and Matplotlib.
Seaborn's lineplot adds one line to the plot. The Matplotlib plot adds another line. So total lines are 2.
Which option best describes the visual style of the histogram after applying Seaborn's whitegrid style?
import matplotlib.pyplot as plt import seaborn as sns import numpy as np sns.set_style('whitegrid') data = np.random.normal(size=100) plt.hist(data, bins=10) plt.show()
Recall what whitegrid style does in Seaborn.
The whitegrid style adds a white background with gray grid lines behind the plot elements, so the histogram bars appear with grid lines behind them on a white background.
What error will this code raise?
import matplotlib.pyplot as plt import seaborn as sns sns.set_style('dark') plt.bar([1, 2, 3], [4, 5]) plt.show()
Check the lengths of the x and height lists passed to plt.bar.
The plt.bar function requires the x and height lists to be the same length. Here, x has 3 elements but height has 2, causing a ValueError.
You want to create a scatter plot with Seaborn and then add a horizontal line at y=0.5 using Matplotlib. Which code snippet correctly achieves this?
Remember which library provides axhline and how to combine plots.
Seaborn does not have axhline. It is a Matplotlib function. So you create the scatter plot with Seaborn, then add the horizontal line with Matplotlib's plt.axhline, then show the plot.