0
0
Matplotlibdata~15 mins

Rcparams for global defaults in Matplotlib - Mini Project: Build & Apply

Choose your learning style9 modes available
Setting Global Plot Styles with RcParams in Matplotlib
📖 Scenario: You are preparing multiple charts for a presentation. You want all your plots to have the same style, like font size and line width, so they look consistent without changing each plot separately.
🎯 Goal: Learn how to set global default styles for all plots using matplotlib.rcParams. You will create a simple plot and change the global font size and line width so every plot uses these settings automatically.
📋 What You'll Learn
Create a dictionary with some sample data for plotting
Set global style defaults using matplotlib.rcParams
Plot the data using the default styles
Print the current global font size and line width settings
💡 Why This Matters
🌍 Real World
Setting global plot styles helps keep all charts in reports or presentations consistent and saves time by avoiding repeated style settings.
💼 Career
Data scientists and analysts often customize plot styles globally to maintain brand colors and readability in dashboards and reports.
Progress0 / 4 steps
1
Create sample data for plotting
Create a dictionary called data with keys 'x' and 'y'. Set 'x' to the list [1, 2, 3, 4, 5] and 'y' to the list [2, 3, 5, 7, 11].
Matplotlib
Need a hint?

Use a dictionary with keys 'x' and 'y' and assign the exact lists as values.

2
Set global font size and line width using rcParams
Import matplotlib.pyplot as plt. Then set the global font size to 14 and the global line width to 3 using plt.rcParams.
Matplotlib
Need a hint?

Use plt.rcParams['font.size'] = 14 and plt.rcParams['lines.linewidth'] = 3 to set global styles.

3
Plot the data using the global defaults
Use plt.plot() to plot data['x'] and data['y']. Then call plt.show() to display the plot.
Matplotlib
Need a hint?

Use plt.plot(data['x'], data['y']) and then plt.show() to display the plot.

4
Print the current global font size and line width
Print the values of plt.rcParams['font.size'] and plt.rcParams['lines.linewidth'] on separate lines.
Matplotlib
Need a hint?

Use print(plt.rcParams['font.size']) and print(plt.rcParams['lines.linewidth']) to show the current settings.