0
0
Matplotlibdata~20 mins

Customizing Seaborn plots with Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Seaborn Matplotlib Customizer
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Seaborn plot customization code?

Consider the following Python code using Seaborn and Matplotlib:

import seaborn as sns
import matplotlib.pyplot as plt

sns.set_theme(style="darkgrid")
data = sns.load_dataset("tips")
plot = sns.scatterplot(x="total_bill", y="tip", data=data)
plot.set_title("Total Bill vs Tip")
plot.set_xlabel("Bill Amount")
plot.set_ylabel("Tip Amount")
plt.show()

What will be the title of the plot?

Matplotlib
import seaborn as sns
import matplotlib.pyplot as plt

sns.set_theme(style="darkgrid")
data = sns.load_dataset("tips")
plot = sns.scatterplot(x="total_bill", y="tip", data=data)
plot.set_title("Total Bill vs Tip")
plot.set_xlabel("Bill Amount")
plot.set_ylabel("Tip Amount")
plt.show()
ATotal Bill vs Tip
BBill Amount vs Tip Amount
CScatterplot of Tips
DNo title will be shown
Attempts:
2 left
💡 Hint

Look at the set_title method call on the plot object.

data_output
intermediate
2:00remaining
How many ticks will be on the x-axis after this customization?

Given this code snippet:

import seaborn as sns
import matplotlib.pyplot as plt

sns.set_theme()
data = sns.load_dataset("iris")
plot = sns.boxplot(x="species", y="sepal_length", data=data)
plot.set_xticks([0, 1, 2])
plt.show()

How many tick labels will appear on the x-axis?

Matplotlib
import seaborn as sns
import matplotlib.pyplot as plt

sns.set_theme()
data = sns.load_dataset("iris")
plot = sns.boxplot(x="species", y="sepal_length", data=data)
plot.set_xticks([0, 1, 2])
plt.show()
A1
B4
C0
D3
Attempts:
2 left
💡 Hint

Check the list passed to set_xticks.

visualization
advanced
2:00remaining
Which option produces a Seaborn line plot with a red dashed line?

Which code snippet will produce a Seaborn line plot with the line colored red and dashed?

Asns.lineplot(x=[1,2,3], y=[4,5,6], style='--', color='red')
Bsns.lineplot(x=[1,2,3], y=[4,5,6], linestyle='--', color='red')
Csns.lineplot(x=[1,2,3], y=[4,5,6], line_style='dashed', color='red')
Dsns.lineplot(x=[1,2,3], y=[4,5,6], linestyle='dotted', color='red')
Attempts:
2 left
💡 Hint

Check the correct parameter name for line style in Seaborn.

🔧 Debug
advanced
2:00remaining
What error does this code raise when customizing a Seaborn plot?

Examine this code:

import seaborn as sns
import matplotlib.pyplot as plt

data = sns.load_dataset("diamonds")
plot = sns.histplot(data["carat"])
plot.set_xlabel("Carat Weight")
plot.set_ylabel("Frequency")
plot.set_title("Carat Distribution")
plot.set_xticks([0.5, 1.0, 1.5, 2.0])
plt.show()

What error will this code raise?

Matplotlib
import seaborn as sns
import matplotlib.pyplot as plt

data = sns.load_dataset("diamonds")
plot = sns.histplot(data["carat"])
plot.set_xlabel("Carat Weight")
plot.set_ylabel("Frequency")
plot.set_title("Carat Distribution")
plot.set_xticks([0.5, 1.0, 1.5, 2.0])
plt.show()
ANo error, plot displays correctly
BTypeError: set_xticks() argument must be a list of integers
CAttributeError: 'AxesSubplot' object has no attribute 'set_xticks'
DValueError: Invalid tick positions
Attempts:
2 left
💡 Hint

Check if set_xticks is a valid method for the plot object.

🚀 Application
expert
3:00remaining
After customizing a Seaborn barplot, what is the color of the bars?

Given this code:

import seaborn as sns
import matplotlib.pyplot as plt

sns.set_theme(style="whitegrid")
data = sns.load_dataset("penguins")
plot = sns.barplot(x="species", y="flipper_length_mm", data=data, color="skyblue")
for bar in plot.patches:
    bar.set_facecolor("orange")
plt.show()

What color will the bars appear in the final plot?

Matplotlib
import seaborn as sns
import matplotlib.pyplot as plt

sns.set_theme(style="whitegrid")
data = sns.load_dataset("penguins")
plot = sns.barplot(x="species", y="flipper_length_mm", data=data, color="skyblue")
for bar in plot.patches:
    bar.set_facecolor("orange")
plt.show()
AGreen
BSkyblue
COrange
DDefault Seaborn color
Attempts:
2 left
💡 Hint

Consider the effect of the loop changing bar face colors after initial color setting.