0
0
Matplotlibdata~20 mins

Style sheets (ggplot, seaborn, dark_background) in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Style Sheet Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
visualization
intermediate
2:00remaining
Effect of ggplot style on a line plot
You run the following code to plot a simple line graph using matplotlib with the ggplot style applied. What will be the main visible difference compared to the default style?
Matplotlib
import matplotlib.pyplot as plt
plt.style.use('ggplot')
plt.plot([1, 2, 3, 4], [10, 20, 25, 30])
plt.show()
AThe plot will have a gray background with white grid lines and red plot lines.
BThe plot will have no grid and blue plot lines on a white background.
CThe plot will have a dark background with bright colored lines and no grid.
DThe plot will have a white grid with red lines and a light gray background.
Attempts:
2 left
💡 Hint
Think about how ggplot style changes the background and grid colors.
Predict Output
intermediate
2:00remaining
Output colors with dark_background style
What color will the line plot be when using the dark_background style with the following code?
Matplotlib
import matplotlib.pyplot as plt
plt.style.use('dark_background')
plt.plot([1, 2, 3], [4, 5, 6])
plt.show()
AThe line will be blue on a gray background.
BThe line will be black on a white background.
CThe line will be white on a black background.
DThe line will be red on a white background.
Attempts:
2 left
💡 Hint
Consider what the dark_background style does to the figure background and default line colors.
data_output
advanced
2:00remaining
Number of grid lines with seaborn style
Using the seaborn style, you plot a line graph with x values from 0 to 4 and y values as their squares. How many vertical grid lines will appear by default?
Matplotlib
import matplotlib.pyplot as plt
plt.style.use('seaborn')
plt.plot(range(5), [x**2 for x in range(5)])
plt.show()
ANo vertical grid lines
B5 vertical grid lines
C4 vertical grid lines
D6 vertical grid lines
Attempts:
2 left
💡 Hint
Check how matplotlib sets ticks and grids by default with seaborn style.
🧠 Conceptual
advanced
2:00remaining
Understanding style sheet impact on plot elements
Which of the following statements about matplotlib style sheets ggplot, seaborn, and dark_background is correct?
A<code>seaborn</code> style adds a white grid on a light gray background and changes font sizes.
B<code>ggplot</code> style uses a dark background and bright colored lines by default.
C<code>dark_background</code> style sets a white background with black grid lines.
D<code>seaborn</code> style disables grid lines by default.
Attempts:
2 left
💡 Hint
Recall the visual themes each style sheet applies.
🔧 Debug
expert
2:00remaining
Why does this style sheet code raise an error?
You run this code but get a FileNotFoundError. What is the cause?
Matplotlib
import matplotlib.pyplot as plt
plt.style.use('seaborn-dark')
plt.plot([1, 2, 3], [3, 2, 1])
plt.show()
AThe plot data lists have different lengths causing an error.
BThe style name 'seaborn-dark' does not exist in matplotlib's default styles.
CThe matplotlib module is not imported correctly.
DThe plot command is missing a required argument.
Attempts:
2 left
💡 Hint
Check the exact style sheet names available in matplotlib.