[bug] rcParams doesn't work first time (v3.5.2)

I think I may have found a bug in v3.5.2. See rcParams doesn't work the first time - Notebook - Jupyter Community Forum. Steps to reproduce

  1. install jupyter=3.5.2 and matplotlib>3 in fresh conda environment from conda-forge channel.
  2. import mpl, set rcParams['figure.figsize'] = (12, 8) and plot anything
  3. figure size is still default.
  4. re-execute cells again, now figure size is updated
  5. downgrade to mpl-3.5.1 and figure size is correctly updated first time

IDK, maybe gh23007 might be related?

Yes, I believe that is the same issue and is fixed by Remove matplotlib rc overrides. by fperez · Pull Request #14 · ipython/matplotlib-inline · GitHub on the matplotlib-inline side (they were setting rcparams on import).

The chain of changes here is that

  1. matplotlib-inline (and the inline backend in IPython that it is the extracted code from) unconditionally set some slightly opinionated rcparams on import
  2. in mpl 3.5.2 we defered actually importing the backend until we actually really had to (when the user first actually creates a figure), previously we did it eagerly at pyplot import.
  3. thus we unintentionally moved the setting of the rcparams in matplotlib-inline until after where you are setting them and hence the squash your changes

I suspect that importing matplotlib-inline before setting the rcparams will fix it as well (but have not verified that).

1 Like