How to customize Matolpotlib using rcParams

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.
This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

How to customize rcParams

To customize rcParams in Matplotlib, we have two options: tweak them during runtime or make lasting modifications to the matplotlibrc file.

Method 1: Changing rcParams at runtime

We can dynamically adjust rcParams in our Python script using the plt.rcParams object. For instance, to alter the font style for text in our plots, we can make the following simple runtime modification:

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

This single line of code will set the font style for all text elements in our subsequent plots to oblique.

Method 2: Modifying the matplotlibrc file

If we want to avoid making changes each time, we can consider tweaking the matplotlibrc file. This file acts as a configuration repository, housing Matplotlib’s default settings. If this file is modified, the customizations propagate across all Matplotlib plots.

The matplotlibrc file’s location varies depending on the system, but we can find it by running the following Python command:

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

Once we’ve located the file, we open it in a text editor and search for lines corresponding to the settings we wish to modify. For example, to tweak the default font style, we can seek out the font.style command and adjust its value. Then, we save the file, and voila! The customizations will adorn all our future figures.

Useful customization options

Because we now have access to the core settings of the Matplotlib library, let’s explore some useful customization options we can use for our plotting needs.

The axes category

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.
This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.
This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

The figure category

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.
This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

The font category

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.
This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

The grid category

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.
This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

The legend category

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.
This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

The lines category

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.
This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

The mathtext category

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.
This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

The patch category

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.
This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

The savefig category

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.
This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

Try it yourself

Here, we’ve provided a playground with a sample plot to try different customization options by changing the rcParams. You can explore different options from the rc file and make the perfect theme for yourself!

This widget is not supported in dev-mode. Kindly enable it or run using yarn webapp:dev-widgets.

Conclusion

Becoming proficient in the art of customizing Matplotlib through rcParams is a valuable skill for crafting visually appealing and coherent data visualizations. Whether it’s adjusting font sizes, altering marker styles, or refining gridline appearances, rcParams empowers us to tailor Matplotlib to our needs. With the knowledge of modifying rcParams at runtime or within the rc file, our plots will convey data effectively and harmonize with our project’s design and style requirements.

Free Resources

Copyright ©2026 Educative, Inc. All rights reserved