What will be the color of the line in the plot after applying the custom style sheet?
import matplotlib.pyplot as plt import matplotlib as mpl custom_style = { 'lines.linewidth': 3, 'lines.color': 'red', 'axes.titlesize': 'large' } mpl.rcParams.update(custom_style) plt.plot([1, 2, 3], [1, 4, 9]) plt.title('Test Plot') plt.show()
Check the lines.linewidth and lines.color keys in the style dictionary.
The custom style sets lines.linewidth to 3, making the line thick, and lines.color to 'red', so the line color is red.
How many style parameters are applied when using the following custom style sheet?
custom_style = {
'lines.linewidth': 2,
'axes.facecolor': 'lightgray',
'grid.color': 'white',
'grid.linestyle': '--'
}
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams.update(custom_style)
params = mpl.rcParams
count = sum(1 for key in custom_style if key in params)
print(count)Count how many keys in custom_style exist in mpl.rcParams.
All 4 keys in the custom style dictionary are valid matplotlib rcParams keys, so all 4 are applied.
What error will occur when running this code?
import matplotlib.pyplot as plt import matplotlib as mpl custom_style = { 'lines.linewidth': 'thick', 'axes.titlesize': 14 } mpl.rcParams.update(custom_style) plt.plot([1, 2, 3], [1, 4, 9]) plt.title('Test Plot') plt.show()
Check the expected data type for lines.linewidth.
The lines.linewidth parameter expects a numeric value (float or int). Passing the string 'thick' causes a TypeError.
Which option best describes the grid appearance after applying this custom style?
import matplotlib.pyplot as plt import matplotlib as mpl custom_style = { 'grid.color': 'green', 'grid.linestyle': ':', 'grid.linewidth': 2 } mpl.rcParams.update(custom_style) plt.plot([1, 2, 3], [1, 4, 9]) plt.grid(True) plt.show()
Look at the grid.color, grid.linestyle, and grid.linewidth values.
The style sets grid color to green, linestyle to dotted (':'), and linewidth to 2 (thick).
Given the following code, what will be the color of the plot line?
import matplotlib.pyplot as plt import matplotlib as mpl mpl.style.use('seaborn-darkgrid') custom_style = { 'lines.color': 'purple', 'lines.linewidth': 1 } mpl.rcParams.update(custom_style) plt.plot([1, 2, 3], [1, 4, 9]) plt.show()
Consider the order of mpl.style.use() calls and which style is applied last.
Styles applied later override earlier ones. The custom style is applied after seaborn, so its settings take priority.