plt.rcParams vs mpl.rcParams

I use the pyplot API rarely [only for whipping up new figures and axes with plt.subplots(with cols, rows, figsize, sharex, sharey etc)] and the rest of my code uses the object oriented API. I was wondering what exactly are the differences in updating the rcParams via modifying the plt.rcParams dictionary vs the mpl.rcParams dictionary? What’s the recommended/best practice? do they always point to the same dictionary object?

(The question assumes the following convention —> “import matplotlib.pyplot as plt”, “import matplotlib as mpl”.)

These always refer to exactly the same object, so you can modify either of them with the same result, it’s really just whatever import is more practical for you.

(PS: I agree with keeping pyplot as far away as possible, except for figure/axes creation.)

1 Like

In general I agree with avoiding the state-based stuff in pyplot. But most of the time I can get away with just import matplotlib.pyplot as plt so plt.rcParams is pretty convenient. I’d be sad to see it go.

1 Like

Yes, once you’ve imported plt for plt.figure() you may as well use plt.rcParams, that’s sort of my point re: whatever import is more practical.

1 Like

Right I think we are on the same page. But we dispense advice like "avoid pyplot", which leads to over-interpretation, whereas what I think we mean is “avoid the state-based assumptions of pyplot, but the explicit parts (like plt.rcParams, plt.subplots) are OK.” We have had people avoid plt.figure in favour of trying to instantiate a figure via Figure, and that is really taking things too far in my opinion.