How to Set Up rcParams in Matplotlib
A simple guide to setting default plotting parameters in matplotlib’s rcParam
--
Matplotlib gets a lot of stick I think it’s unfair. I’ll admit that if you just run plt.plot()
then you’ll get something quite ugly but it is, in my view, the best plotting package in python and a largely unavoidable one.
Alternatives
Ok, so you don’t like matplotlib and are considering something else. Here’s my (brief) take on the popular alternatives.
Seaborn is a popular alternative plotting package that has loads of great additional plot types and will produce slightly better plots out the box. pandas can be used to plot data directly and can handle time series quite nicely, so again is popular among data scientists. However, both seaborn and pandas are matplotlib under the hood and if you want to change their default appearance then you need to know matplotlib. Please don’t get me started on Plotly…
The single greatest thing about matplotlib is the ability to set default plot appearance at the start of a notebook and it apply to all your matplotlib figures — some of these properties also apply to seaborn and pandas plots! There is nothing even remotely similar in Plotly in which every plot must be created from scratch. Although to be fair plotly does look better from the start it’s very cumbersome to update the defaults and the documentation is limited.
In my previous article I talked about how to change the appearance of matplotlib figures. In this article I’ll show you how to set these settings on all your plots using rcParams.
What is rcParams in matplotlib?
It’s a dictionary of most matplotlib styling that you set at the start of your notebook and it will apply to all your plots.
You can import it using the following:
from matplotlib import rcParams
Printing out rcParams
in a notebook you can see the key-value pair structure.