Consider this Python code that uses Matplotlib with Seaborn style applied. What will be the color of the plotted line?
import matplotlib.pyplot as plt plt.style.use('seaborn-darkgrid') plt.plot([1, 2, 3], [4, 5, 6]) plt.gca().lines[0].get_color()
Seaborn's default color palette starts with a specific blue color for the first line.
When using 'seaborn-darkgrid' style, the first line color defaults to '#1f77b4', a blue shade from the default color cycle.
Using the 'seaborn-whitegrid' style, a plot is created with default ticks. How many horizontal grid lines will be visible on the y-axis?
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()])
Count the visible horizontal grid lines generated by default y-axis ticks in Seaborn whitegrid style.
The default y-axis ticks create 5 visible horizontal grid lines in 'seaborn-whitegrid' style.
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
Think about which Seaborn style uses pastel colors and a light gray background with white grid lines.
'seaborn-muted' style uses a light gray background, white grid lines, thin gray spines, and pastel colors for lines.
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?
import matplotlib.pyplot as plt plt.plot([1, 2, 3], [4, 5, 6]) plt.style.use('seaborn-darkgrid') plt.show()
Consider when styles must be set relative to plotting commands.
Matplotlib styles must be set before plotting commands to affect the plot appearance. Here, style is set after plotting, so it does not apply.
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?
Think about the order of applying style and setting rcParams for global effect.
Setting rcParams after applying style overrides the style settings globally. Setting rcParams before style will be overridden by the style. plt.grid() affects only current plot, not global settings.