Don't import rcParams into matplotlib modules directly:
# NO:
from matplotlib import rcParams
...
rcParams[...]
This has the disadvantage that rcParams get into the module namespace and people easily start using that (e.g. from matplotlib import cm; cm.rcParams).
Instead use
# YES:
import matplotlib as mpl
...
mpl.rcParams[...]
While in theory people could still access it via mpl (e.g. cm.mpl.rcParams), this is far more unlikely and good enough for us. - We also don't shield other module imports.
Note: It's also ok to use plt.rcParams if you happen to have pyplot anyway and would have to import mpl. This is in particular true for examples. But most matplotlib modules should not depend on pyplot.
There are many places in the library that need fixing, so it's ok to do this step-by-step.
Activity
oscargus commented on Aug 19, 2022
Great! I seem to recall that I saw this somewhere, but couldn't recall where.
oscargus commented on Aug 19, 2022
Maybe we should consider a test for this to make sure that it is not accidentally added again?
timhoffm commented on Aug 19, 2022
Feel free to do that if you like. However, it's not super important.
timhoffm commented on Dec 22, 2022
This is done. I don't think we need the effort for a test.