Summary
Originally mentioned in #16181 (comment)
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.
Related PRs:
Summary
Originally mentioned in #16181 (comment)
Don't import
rcParamsinto matplotlib modules directly:This has the disadvantage that
rcParamsget into the module namespace and people easily start using that (e.g.from matplotlib import cm; cm.rcParams).Instead use
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.rcParamsif 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 onpyplot.There are many places in the library that need fixing, so it's ok to do this step-by-step.
Related PRs: