Data Science with Python Certification Data Science with Python Matplotlib and Seaborn Visualization 2 — Questions and Answers
Question 1: Which Seaborn function creates a matrix of scatter plots for every pair of variables in a DataFrame?
- sns.heatmap()
- sns.pairplot() (Correct answer)
- sns.jointplot()
- sns.scatterplot()
Correct answer: sns.pairplot()
sns.pairplot() generates a grid of scatter plots for all pairwise combinations of numeric variables.
Question 2: In Matplotlib, which method saves the current figure to a file?
- plt.export()
- plt.savefig() (Correct answer)
- plt.write()
- plt.store()
Correct answer: plt.savefig()
plt.savefig('filename.png') saves the current figure to disk in the specified format.
Question 3: What does the 'hue' parameter do in Seaborn plots?
- Changes the plot background color
- Maps a third variable to color encoding (Correct answer)
- Sets the color palette globally
- Adjusts the transparency of markers
Correct answer: Maps a third variable to color encoding
The 'hue' parameter encodes an additional categorical or numeric variable through color differentiation.
Question 4: Which Matplotlib function creates a figure with multiple subplots and returns both the figure and axes objects?
- plt.subplot()
- plt.subplots() (Correct answer)
- plt.axes()
- plt.figure()
Correct answer: plt.subplots()
plt.subplots() creates a figure and a grid of subplots, returning (fig, axes) as a tuple.
Question 5: In Seaborn, what is the purpose of sns.set_style('whitegrid')?
- Removes all axis labels
- Sets the background to white with grid lines (Correct answer)
- Makes the plot area transparent
- Changes the font to white
Correct answer: Sets the background to white with grid lines
sns.set_style('whitegrid') applies a white background with grid lines to all subsequent Seaborn plots.
Question 6: Which Matplotlib method changes the x-axis tick labels?
- ax.set_xticks()
- ax.set_xticklabels() (Correct answer)
- ax.xlabel()
- ax.xtick_labels()
Correct answer: ax.set_xticklabels()
ax.set_xticklabels() sets the text labels for the x-axis tick marks.
Question 7: What type of plot does sns.violinplot() combine?
- Bar chart and line chart
- Box plot and kernel density estimate (Correct answer)
- Scatter plot and histogram
- Pie chart and bar chart
Correct answer: Box plot and kernel density estimate
A violin plot combines a box plot's quartile information with a kernel density estimate of the distribution shape.
Which Seaborn function creates a matrix of scatter plots for every pair of variables in a DataFrame?