Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the relationship between Seaborn and Matplotlib when creating plots?
Seaborn is built on top of Matplotlib. It uses Matplotlib's functions to create plots but adds simpler syntax and nicer default styles. You can customize Seaborn plots further using Matplotlib commands.
Click to reveal answer
beginner
How can you change the title font size of a Seaborn plot using Matplotlib?
After creating a Seaborn plot, use Matplotlib's plt.title() or ax.set_title() with the fontsize parameter to change the title size. For example: ax.set_title('My Title', fontsize=16).
Click to reveal answer
beginner
Which Matplotlib object do you often get from a Seaborn plot to customize it?
You usually get an Axes object (often named ax) from Seaborn plotting functions. This object lets you customize labels, titles, ticks, and more using Matplotlib methods.
Click to reveal answer
intermediate
How do you adjust the x-axis label rotation in a Seaborn plot using Matplotlib?
Use the Matplotlib method ax.set_xticklabels() with the rotation parameter. For example: ax.set_xticklabels(ax.get_xticklabels(), rotation=45) rotates labels 45 degrees.
Click to reveal answer
beginner
What Matplotlib function helps you add grid lines to a Seaborn plot?
Use ax.grid(True) to add grid lines. You can customize grid style, color, and width with parameters like linestyle and linewidth.
Click to reveal answer
What object do you get from a Seaborn plot to customize it with Matplotlib?
AAxes object
BFigure object
CDataFrame
DSeries object
✗ Incorrect
Seaborn plotting functions return an Axes object, which you can use to customize the plot with Matplotlib.
How do you change the font size of the plot title in a Seaborn plot?
Aplt.title('Title', fontweight='bold')
Bax.set_title('Title', fontsize=12)
Csns.set_title('Title', size=12)
Dax.title('Title', font=12)
✗ Incorrect
Use ax.set_title() with the fontsize parameter to change the title font size.
Which method rotates x-axis labels in a Seaborn plot?
4. Identify the error in the code below that tries to change the figure size of a Seaborn plot:
import seaborn as sns
import matplotlib.pyplot as plt
sns_plot = sns.barplot(x=[1,2,3], y=[4,5,6])
sns_plot.figure(figsize=(10,5))
plt.show()
medium
A. The correct method is sns_plot.set_figsize(10,5)
B. The figure size should be set using plt.figure(figsize=(10,5)) before plotting
C. sns.barplot does not support figure size changes
D. Figure size cannot be changed after plotting
Solution
Step 1: Understand how to set figure size in Matplotlib
Figure size is set by creating a figure with plt.figure(figsize=(width,height)) before plotting.
Step 2: Identify the mistake in the code
Calling sns_plot.figure(figsize=(10,5)) is incorrect because 'figure' is not a method of the plot object.
Final Answer:
The figure size should be set using plt.figure(figsize=(10,5)) before plotting -> Option B
Quick Check:
Set figure size with plt.figure() before plotting [OK]
Hint: Use plt.figure(figsize=...) before plotting [OK]
Common Mistakes:
Calling figure() on plot object
Trying to set figure size after plot creation
Using non-existent set_figsize method
5. You want to create a Seaborn line plot with a custom figure size of 12x6 inches, a title 'Sales Over Time', X-axis label 'Month', Y-axis label 'Sales', and grid lines visible. Which code snippet correctly achieves this?
hard
A.
import seaborn as sns
import matplotlib.pyplot as plt
plt.figure(figsize=(12,6))
sns.lineplot(x=[1,2,3], y=[100,200,300])
plt.title('Sales Over Time')
plt.xlabel('Month')
plt.ylabel('Sales')
plt.grid(True)
plt.show()
B.
import seaborn as sns
import matplotlib.pyplot as plt
sns.lineplot(x=[1,2,3], y=[100,200,300], figsize=(12,6))
plt.title('Sales Over Time')
plt.xlabel('Month')
plt.ylabel('Sales')
plt.grid(True)
plt.show()
C.
import seaborn as sns
import matplotlib.pyplot as plt
sns.set_figsize(12,6)
sns.lineplot(x=[1,2,3], y=[100,200,300])
plt.title('Sales Over Time')
plt.xlabel('Month')
plt.ylabel('Sales')
plt.grid(True)
plt.show()
D.
import seaborn as sns
import matplotlib.pyplot as plt
plt.figure(figsize=(12,6))
sns.lineplot(x=[1,2,3], y=[100,200,300])
sns.title('Sales Over Time')
sns.xlabel('Month')
sns.ylabel('Sales')
sns.grid(True)
plt.show()
Solution
Step 1: Set figure size before plotting
Use plt.figure(figsize=(12,6)) to set the plot size before creating the plot.
Step 2: Use Matplotlib functions for title, labels, and grid
Matplotlib functions plt.title(), plt.xlabel(), plt.ylabel(), and plt.grid(True) customize the plot after creation.
Step 3: Verify code correctness
import seaborn as sns
import matplotlib.pyplot as plt
plt.figure(figsize=(12,6))
sns.lineplot(x=[1,2,3], y=[100,200,300])
plt.title('Sales Over Time')
plt.xlabel('Month')
plt.ylabel('Sales')
plt.grid(True)
plt.show()
correctly uses plt.figure and Matplotlib functions; other options misuse parameters or functions.
Final Answer:
plt.figure(figsize=(12,6)); sns.lineplot(); plt.title('Sales Over Time'); plt.xlabel('Month'); plt.ylabel('Sales'); plt.grid(True) -> Option A
Quick Check:
Set figure size with plt.figure, customize with plt functions [OK]
Hint: Set size with plt.figure, customize with plt.title/labels/grid [OK]