Consider this code snippet that changes a global default in matplotlib using rcParams. What will be the color of the line in the plot?
import matplotlib.pyplot as plt plt.rcParams['lines.color'] = 'red' plt.plot([1, 2, 3], [4, 5, 6]) line_color = plt.gca().lines[0].get_color() print(line_color)
Changing plt.rcParams['lines.color'] sets the default line color globally.
The rcParams dictionary controls default styles in matplotlib. Setting lines.color to 'red' changes the default line color to red, so the plotted line will be red.
After running the following code, what is the default font size used in matplotlib plots?
import matplotlib.pyplot as plt plt.rcParams['font.size'] = 14 font_size = plt.rcParams['font.size'] print(font_size)
Look at the value assigned to plt.rcParams['font.size'].
Setting plt.rcParams['font.size'] to 14 changes the default font size for all text in matplotlib plots to 14 points.
Look at this code snippet:
import matplotlib.pyplot as plt plt.rcParams['axes.facecolor'] = 'yellow' plt.plot([1, 2, 3], [4, 5, 6]) plt.show()
The plot background color does not change to yellow. Why?
Check if any style or context is overriding rcParams after setting it.
If a style or context is applied after setting rcParams, it can override those settings. The key 'axes.facecolor' is correct, and the background color can be changed at any time. The issue is that a style is overriding the rcParams change.
In matplotlib, which rcParams key sets the default style of grid lines?
Look for the key that controls line style specifically for grid lines.
The correct key is 'grid.linestyle'. It controls the pattern of grid lines, such as solid, dashed, or dotted. Other options are invalid keys or control different properties.
You want to set the default line width to 3 and the default marker size to 10 for all plots globally using rcParams. Which code snippet achieves this?
Check the exact keys for line width and marker size in rcParams.
The keys 'lines.linewidth' and 'lines.markersize' control the default line width and marker size respectively. The values must be set accordingly. Other keys are invalid or swapped values.