Challenge - 5 Problems
Style Sheet Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ visualization
intermediate2: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()
Attempts:
2 left
💡 Hint
Think about how ggplot style changes the background and grid colors.
✗ Incorrect
The ggplot style in matplotlib sets a gray background with white grid lines and red plot lines by default. This mimics the ggplot2 style from R.
❓ Predict Output
intermediate2:00remaining
Output colors with
dark_background styleWhat 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()
Attempts:
2 left
💡 Hint
Consider what the dark_background style does to the figure background and default line colors.
✗ Incorrect
The dark_background style sets the figure background to black and the default line color to white for good contrast.
❓ data_output
advanced2:00remaining
Number of grid lines with
seaborn styleUsing 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()
Attempts:
2 left
💡 Hint
Check how matplotlib sets ticks and grids by default with seaborn style.
✗ Incorrect
By default, matplotlib places ticks at the edges and between points, so for 5 x values, 6 vertical grid lines appear with seaborn style.
🧠 Conceptual
advanced2:00remaining
Understanding style sheet impact on plot elements
Which of the following statements about matplotlib style sheets
ggplot, seaborn, and dark_background is correct?Attempts:
2 left
💡 Hint
Recall the visual themes each style sheet applies.
✗ Incorrect
The seaborn style applies a light gray background with white grid lines and adjusts font sizes for clarity. The other options incorrectly describe the styles.
🔧 Debug
expert2: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()
Attempts:
2 left
💡 Hint
Check the exact style sheet names available in matplotlib.
✗ Incorrect
The style seaborn-dark is not a valid default style in matplotlib, so trying to use it raises a FileNotFoundError.