0
0
Matplotlibdata~20 mins

Rcparams for global defaults in Matplotlib - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Rcparams Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this rcParams change?

Consider this code snippet that changes a global default in matplotlib using rcParams. What will be the color of the line in the plot?

Matplotlib
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)
A'black'
B'blue'
C'green'
D'red'
Attempts:
2 left
💡 Hint

Changing plt.rcParams['lines.color'] sets the default line color globally.

data_output
intermediate
1:30remaining
What is the default font size after this rcParams update?

After running the following code, what is the default font size used in matplotlib plots?

Matplotlib
import matplotlib.pyplot as plt
plt.rcParams['font.size'] = 14
font_size = plt.rcParams['font.size']
print(font_size)
A14.0
B12.0
C10.0
D16.0
Attempts:
2 left
💡 Hint

Look at the value assigned to plt.rcParams['font.size'].

🔧 Debug
advanced
2:30remaining
Why does this rcParams setting not change the plot background color?

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?

AThe plot uses a style that overrides rcParams, so the change is ignored.
BThe key 'axes.facecolor' is misspelled and should be 'axes.face_color'.
CThe background color changes only if set before importing matplotlib.
DThe plot background color is controlled by 'figure.facecolor', not 'axes.facecolor'.
Attempts:
2 left
💡 Hint

Check if any style or context is overriding rcParams after setting it.

🧠 Conceptual
advanced
1:30remaining
Which rcParams key controls the default grid line style?

In matplotlib, which rcParams key sets the default style of grid lines?

A'grid.linewidth'
B'grid.linestyle'
C'grid.line_style'
D'grid.style'
Attempts:
2 left
💡 Hint

Look for the key that controls line style specifically for grid lines.

🚀 Application
expert
3:00remaining
How to globally set all line widths to 3 and marker size to 10 using rcParams?

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?

A
import matplotlib.pyplot as plt
plt.rcParams['line.width'] = 3
plt.rcParams['marker.size'] = 10
B
import matplotlib.pyplot as plt
plt.rcParams['lines.width'] = 3
plt.rcParams['markers.size'] = 10
C
import matplotlib.pyplot as plt
plt.rcParams['lines.linewidth'] = 3
plt.rcParams['lines.markersize'] = 10
D
import matplotlib.pyplot as plt
plt.rcParams['lines.linewidth'] = 10
plt.rcParams['lines.markersize'] = 3
Attempts:
2 left
💡 Hint

Check the exact keys for line width and marker size in rcParams.