Concept Flow - Rcparams for global defaults
Start Program
Import matplotlib
Set rcParams globally
Plot graph
Graph uses rcParams settings
End Program
This flow shows how setting rcParams affects all plots globally in matplotlib.
import matplotlib.pyplot as plt plt.rcParams['lines.linewidth'] = 3 plt.plot([1, 2, 3], [1, 4, 9]) plt.show()
| Step | Action | rcParams['lines.linewidth'] | Plot Line Width | Output |
|---|---|---|---|---|
| 1 | Import matplotlib.pyplot as plt | default (1.5) | N/A | No plot yet |
| 2 | Set plt.rcParams['lines.linewidth'] = 3 | 3 | N/A | No plot yet |
| 3 | Call plt.plot with data | 3 | 3 | Line plot prepared with width 3 |
| 4 | Call plt.show() | 3 | 3 | Plot displayed with thick line width 3 |
| Variable | Start | After Step 2 | After Step 3 | Final |
|---|---|---|---|---|
| rcParams['lines.linewidth'] | 1.5 (default) | 3 | 3 | 3 |
| Plot Line Width | N/A | N/A | 3 | 3 |
matplotlib.rcParams is a global dictionary for default plot styles. Change rcParams values to set global defaults (e.g., line width). All plots created after the change use these new defaults. Example: plt.rcParams['lines.linewidth'] = 3 sets thicker lines globally. Use plt.show() to display plots with updated styles.