question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

matplotlib's rcParams['figure.figsize'] lost between cells

See original GitHub issue

I can set the size of figures like this:

# In[1]:
import matplotlib.pyplot as plt
import numpy as np

%matplotlib inline

x = np.linspace(0, 6, 200)
y = np.sin(x)

# In[2]:
# Set figures to be large
plt.rcParams['figure.figsize'] = (10, 10)
plt.plot(x, y);

In the above example, the rcParams[‘figure.figsize’] is set in cell 2 (where the plot is made), and the figure is correctly sized to 10 x 10.

However, if I try setting the figure size in cell 1, it is ignored. The figure remains the default size…

# In[1]:
import matplotlib.pyplot as plt
import numpy as np

%matplotlib inline

x = np.linspace(0, 6, 200)
y = np.sin(x)

# Set figures to be large
plt.rcParams['figure.figsize'] = (10, 10)

# In[2]:
plt.plot(x, y);

Settings in rcParams used to work. It must be an updated version of ipython or matplotlib which has broken the memory of rcParams between cells.

The output of pandas.show_versions() is:

INSTALLED VERSIONS
------------------
commit: None
python: 3.6.4.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None

pandas: 0.22.0
pytest: 3.2.1
pip: 9.0.1
setuptools: 36.5.0.post20170921
Cython: 0.26.1
numpy: 1.13.3
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.2
feather: None
matplotlib: 2.2.2
openpyxl: 2.4.8
xlrd: 1.1.0
xlwt: 1.3.0
xlsxwriter: 0.9.8
lxml: 3.8.0
bs4: 4.6.0
html5lib: 0.999999999
sqlalchemy: 1.1.13
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:8
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
mapiocommented, Dec 4, 2018

For me this happens if I put import matplotlib.pylab as plt in the same cell as plt.rcParams['figure.figsize'] = … but not if I put it in two cells.

screen shot 2018-12-04 at 22 08 50 screen shot 2018-12-04 at 22 09 08  
5reactions
germannpcommented, Nov 20, 2018

For me it is even weirder:

grafik

But if I run everything again, it works:

grafik

  • Windows 10 Enterprise, 1803
  • Matplotlib 2.2.3
  • Python 3.7.0
  • JupyterLab 0.34.9
Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I change the size of figures drawn with Matplotlib?
plot() for example, you can set a tuple with width and height. import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = (20, ...
Read more >
matplotlib.pyplot.figure — Matplotlib 3.1.0 documentation
If this figure does not exists, create it and returns it. If num is a string, the window title will be set to...
Read more >
rcParams doesn't work the first time - Notebook
If I create two cells: #%% 1st Cell import matplotlib as mpl from matplotlib import ... rcParams['figure.figsize'] = (12, 8) #%% 2nd cell...
Read more >
Chapter 4. Visualization with Matplotlib - O'Reilly
Selection from Python Data Science Handbook [Book] ... types of flowers that has had the size of its petals and sepals carefully measured...
Read more >
Python Plotting With Matplotlib (Guide)
Almost all functions from pyplot, such as plt.plot() , are implicitly either referring to an existing current Figure and current Axes, or creating...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found