Matplotlib: Make Your Plotting Life Easier with rcParams | by Mike Clayton | Feb, 2024

Editor
2 Min Read


Visualisation

Consistently beautiful plots with less code and minimal effort

A boxplot comparing fake earnings data between industries with styling using matplotlib’s rcParams
A boxplot using rcParams for styling — Image by Author

Matplotlib is undoubtedly a powerful and extensible plotting library, but it can also be frustratingly complicated, and in particular, very verbose.

rcParams (runtime configuration parameters) provide a way of extracting some of the boilerplate code into a configuration file. This results in significantly less repeated code, and consistently beautiful and well laid out plots. It also makes your setup and styling replicable, and easily transportable between projects.

As I mentioned in my previous article that compared Matplotlib to some of the other popular plotting libraries (such as Seaborn or plotnine):

It [Matplotlib] is fairly ubiquitous in the field of data science, and it would be fair to say that a lot of people have a love-hate relationship with it. It is very flexible, but can also get quite involved.

Me in my previous article

“Quite involved” could be a number of things. In particular it became quite obvious that all the other libraries excelled at one thing that Matplotlib didn’t. They could all generate quite attractive well laid out plots with very little code input.

They [the alternative plotting libraries] could all generate quite attractive well laid out plots with very little code input.

So is there a way that Matplotlib can compete with this instant gratification, without losing the flexibility and plotting prowess it is famous for? As pointed out by one of the commenters of that previous article it certainly is:

On the other hand, yes — matplotlib is ugly by default. But as you keep on learning it, you’ll get to know the so called `rcParams` — a file that provides all the initial plot settings.

Pawel Jastrzebski

…and he is right. So let’s see how this can be put into action.

Share this Article
Please enter CoinGecko Free Api Key to get this plugin works.