Data Science with Python Certification Data Science with Python Matplotlib and Seaborn Visualization 4 — Questions and Answers
Question 1: Which Seaborn function plots the distribution of a single variable alongside a scatter plot of two variables?
- sns.pairplot()
- sns.jointplot() (Correct answer)
- sns.displot()
- sns.rugplot()
Correct answer: sns.jointplot()
sns.jointplot() displays a bivariate scatter (or other plot) in the center with marginal univariate distributions on the axes.
Question 2: In Matplotlib, what does plt.tight_layout() do?
- Compresses the figure to a smaller size
- Automatically adjusts subplot parameters to prevent overlap (Correct answer)
- Locks the axis scales
- Sets uniform padding on all sides
Correct answer: Automatically adjusts subplot parameters to prevent overlap
plt.tight_layout() automatically adjusts subplot spacing so titles, labels, and tick marks don't overlap.
Question 3: Which parameter in sns.scatterplot() controls the size of each point based on a variable?
- size (Correct answer)
- markersize
- scale
- pointsize
Correct answer: size
The 'size' parameter maps a numeric variable to the area of each scatter point, adding a fourth data dimension.
Question 4: What is the effect of calling plt.yscale('log') in Matplotlib?
- Normalizes y-axis values between 0 and 1
- Sets the y-axis to a logarithmic scale (Correct answer)
- Displays y-axis labels in scientific notation
- Inverts the y-axis direction
Correct answer: Sets the y-axis to a logarithmic scale
plt.yscale('log') changes the y-axis to a logarithmic scale, useful for data spanning several orders of magnitude.
Question 5: In Seaborn, what does the 'order' parameter do in categorical plots like sns.boxplot()?
- Sorts the data values within each box
- Controls the left-to-right display order of categories (Correct answer)
- Sets the color order of the palette
- Determines the rendering z-order
Correct answer: Controls the left-to-right display order of categories
The 'order' parameter accepts a list of category names to control the sequence in which they appear on the axis.
Question 6: Which Matplotlib function creates a horizontal bar chart?
- plt.bar()
- plt.barh() (Correct answer)
- plt.hbar()
- plt.horizontal_bar()
Correct answer: plt.barh()
plt.barh() creates a horizontal bar chart, where bars extend left or right instead of up or down.
Question 7: What does sns.FacetGrid allow you to do in Seaborn?
- Merge two DataFrames before plotting
- Create a grid of plots conditioned on one or more variables (Correct answer)
- Generate 3D faceted plots
- Apply custom color palettes across subplots
Correct answer: Create a grid of plots conditioned on one or more variables
FacetGrid creates a multi-panel figure where each panel shows a subset of data based on the values of conditioning variables.
Which Seaborn function plots the distribution of a single variable alongside a scatter plot of two variables?