Data Science with Python Certification Data Science with Python Matplotlib and Seaborn Visualization 5 — Questions and Answers
Question 1: Which Seaborn palette would be most appropriate for displaying diverging data centered around zero?
- 'viridis'
- 'coolwarm' (Correct answer)
- 'Blues'
- 'Set1'
Correct answer: 'coolwarm'
The 'coolwarm' palette is a diverging palette that transitions from blue (negative) through white (zero) to red (positive).
Question 2: In Matplotlib, how do you plot a second dataset on a shared x-axis with a separate y-axis?
- Use plt.twinx() to create a second axes sharing the x-axis (Correct answer)
- Use plt.twiny() to create a second axes sharing the x-axis
- Use ax.secondary_axis('right')
- Use plt.subplot(1,2,2) for the second dataset
Correct answer: Use plt.twinx() to create a second axes sharing the x-axis
ax.twinx() creates a new axes that shares the same x-axis but has an independent y-axis on the right side.
Question 3: What happens when you pass annot=True to sns.heatmap()?
- Adds axis labels automatically
- Displays the numeric value inside each cell (Correct answer)
- Highlights the maximum value in each row
- Adds a color bar annotation
Correct answer: Displays the numeric value inside each cell
annot=True causes sns.heatmap() to write the data value as text inside each colored cell of the heatmap.
Question 4: Which Matplotlib method changes the range of values displayed on the x-axis?
- ax.set_xlim() (Correct answer)
- ax.xlim()
- ax.set_xrange()
- ax.xbound()
Correct answer: ax.set_xlim()
ax.set_xlim(min, max) sets the lower and upper bounds of the x-axis display range.
Question 5: In Seaborn, what does the 'col' parameter in sns.FacetGrid accomplish?
- Sets the color of all plot elements
- Creates separate subplot columns for each unique value of the variable (Correct answer)
- Specifies the column of the DataFrame to plot
- Adjusts the number of color levels
Correct answer: Creates separate subplot columns for each unique value of the variable
The 'col' parameter splits the data by a categorical variable and creates a separate subplot column for each unique value.
Question 6: Which Matplotlib function is used to add text annotations to a specific point on a plot?
- plt.text()
- plt.annotate() (Correct answer)
- plt.label()
- plt.mark()
Correct answer: plt.annotate()
plt.annotate() adds text with an optional arrow pointing to a specific data coordinate, making it ideal for highlighting points.
Question 7: What is the key advantage of using Seaborn's object-oriented API (e.g., sns.objects) over the function-based API?
- It runs faster due to compiled C extensions
- It enables composable, layered plot construction with method chaining (Correct answer)
- It automatically selects the best chart type
- It removes the dependency on Matplotlib entirely
Correct answer: It enables composable, layered plot construction with method chaining
Seaborn's objects API allows layering multiple marks and transformations through method chaining, providing more flexible and composable plot construction.
Which Seaborn palette would be most appropriate for displaying diverging data centered around zero?