notebook
notebook copied to clipboard
matplotlib rcParams not taking effect until after the first plot
trafficstars
Describe the bug matplotlib rcParams not taking effect until after the first plot. Apologies if this is not a jupyter notebook issue!
To Reproduce
I have the following Jupyter Notebook (in percent format)
# %%
import matplotlib.pyplot as plt
# %%
plt.rcParams['figure.figsize'] = (16, 9)
# %%
print(plt.rcParams['figure.figsize']) # prints [16.0, 9.0]
plt.plot(range(100), range(100)) # shows default size (not 16x9) plot
# %%
plt.rcParams['figure.figsize'] = (16, 9)
# %%
plt.plot(range(100), range(100)) # shows large size (16x9) plot
It seems like rcParams has to be set after the first plot in order to work.
Using a fresh conda environment
# Name Version Build Channel
ipython 8.4.0 py310hbe9552e_0 conda-forge
matplotlib 3.5.2 py310hb6292c7_1 conda-forge
notebook 6.4.12 pyha770c72_0 conda-forge
...
I can also reproduce the issue using Jupyter Lab.
I am not able to reproduce the issue in ipython
# In [1]:
%matplotlib inline
# In [2]:
import matplotlib.pyplot as plt
# In [3]:
plt.rcParams['figure.figsize'] = (16, 9)
# In [4]:
plt.plot(range(100), range(100)) # large size (16x9) plot
# Out[4]:
[<matplotlib.lines.Line2D at 0x115a4f7c0>]
<Figure size 1152x648 with 1 Axes>
Desktop:
- OS: macOS Monterey Version 12.5 (arm64)
- Browser: Firefox
Additional context These issues are different but related
- https://github.com/jupyter/notebook/issues/3385
- https://github.com/ipython/ipython/issues/11098