0
0
Matplotlibdata~20 mins

Seaborn style with Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Seaborn Style Master
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 code using Seaborn style?

Consider this Python code that uses Matplotlib with Seaborn style applied. What will be the color of the plotted line?

Matplotlib
import matplotlib.pyplot as plt
plt.style.use('seaborn-darkgrid')
plt.plot([1, 2, 3], [4, 5, 6])
plt.gca().lines[0].get_color()
A'#ff7f0e'
B'#d62728'
C'#2ca02c'
D'#1f77b4'
Attempts:
2 left
💡 Hint

Seaborn's default color palette starts with a specific blue color for the first line.

data_output
intermediate
2:00remaining
How many grid lines are visible with Seaborn style?

Using the 'seaborn-whitegrid' style, a plot is created with default ticks. How many horizontal grid lines will be visible on the y-axis?

Matplotlib
import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
fig, ax = plt.subplots()
ax.plot([0, 1, 2], [0, 1, 4])
ax.yaxis.get_gridlines()
len([line for line in ax.yaxis.get_gridlines() if line.get_visible()])
A6
B5
C4
D7
Attempts:
2 left
💡 Hint

Count the visible horizontal grid lines generated by default y-axis ticks in Seaborn whitegrid style.

visualization
advanced
2:30remaining
Identify the style used from the plot appearance

Below is a description of a plot's appearance. Which Seaborn style was used with Matplotlib?

  • Background is light gray
  • Grid lines are white and visible
  • Axes spines are thin and gray
  • Lines use a pastel color palette
A'seaborn-muted'
B'seaborn-dark'
C'seaborn-ticks'
D'seaborn-poster'
Attempts:
2 left
💡 Hint

Think about which Seaborn style uses pastel colors and a light gray background with white grid lines.

🔧 Debug
advanced
2:00remaining
Why does this code not apply Seaborn style correctly?

Examine this code snippet. It tries to apply Seaborn style to a Matplotlib plot but the plot looks like default Matplotlib style. What is the reason?

Matplotlib
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.style.use('seaborn-darkgrid')
plt.show()
AMatplotlib does not support Seaborn styles directly.
BThe style name 'seaborn-darkgrid' is invalid and ignored.
CStyle is applied after plotting, so it has no effect on the plot.
DThe plot command is missing a color argument to show style.
Attempts:
2 left
💡 Hint

Consider when styles must be set relative to plotting commands.

🚀 Application
expert
3:00remaining
Combine Seaborn style with custom Matplotlib settings

You want to use the 'seaborn-dark' style but change the grid line color to red and line width to 2 for all plots in your script. Which code snippet achieves this correctly?

A
import matplotlib.pyplot as plt
plt.style.use('seaborn-dark')
plt.rcParams['grid.color'] = 'red'
plt.rcParams['grid.linewidth'] = 2
B
import matplotlib.pyplot as plt
plt.rcParams['grid.color'] = 'red'
plt.rcParams['grid.linewidth'] = 2
plt.style.use('seaborn-dark')
C
import matplotlib.pyplot as plt
plt.style.use('seaborn-dark')
plt.setp(plt.gca().gridlines, color='red', linewidth=2)
D
import matplotlib.pyplot as plt
plt.style.use('seaborn-dark')
plt.grid(color='red', linewidth=2)
Attempts:
2 left
💡 Hint

Think about the order of applying style and setting rcParams for global effect.