Notebook: matplotlib rcParams are not picked up from if "%matplolib inline" is in the same cell

Created on 28 Feb 2018  路  8Comments  路  Source: jupyter/notebook

Hello all. It looks like %matplotlib inline does not go along with matplotlib.rcParams:

If trying to assign matplotlib.rcParams together with the magic %matplotlib inline in one cell, then rcParams are reset after the cell is executed:

image

But without %matplotlib inline it works as it should

image

matplolib 2.1.2
notebook 5.4.0
IPython 6.2.1
OS Windows 7

Most helpful comment

Running
matplotlib 3.0.2
notebook 5.7.2
ipython 7.1.1

I also have this issue.

I do, however, not believe that it is related to the %matplotlib inline magic. It also happens, for me at least, if you only import matplotlib or import matplotlib.pyplot. And it seems to affect only certain rcParams. Font size is affected as well but setting 'text.usetex' works.

All 8 comments

Confirming this as a regression; the code as shown in Cell 1 above used to work fine. For those arriving via some search engine wondering what to do, splitting out all the calls to rcParams calls into the next cell is a workaround.

Thank you. I wasted way too much time trying to figure out why my figures weren't working.

Possibly related https://github.com/ipython/ipython/issues/11098

Running
matplotlib 3.0.2
notebook 5.7.2
ipython 7.1.1

I also have this issue.

I do, however, not believe that it is related to the %matplotlib inline magic. It also happens, for me at least, if you only import matplotlib or import matplotlib.pyplot. And it seems to affect only certain rcParams. Font size is affected as well but setting 'text.usetex' works.

I confirm what @findesgh finds. The behaviour is there even if I omit %matplotlib inline and use plt.show() instead.

Screenshot 2019-08-08 10 59 57

Screenshot 2019-08-08 10 59 28

A work-around that solved the problem here
Run your cells first with

%matplotlib notebook

Then configuration works. You can now set inline back again, and it will work.

I think jupyter overrides the rc settings somewhere.

I think I have a related problem: when I import pyplot in a Jupyter notebook, the plots do not use the parameter settings from the matplotlibrc file.

I agree that jupyter is overriding the rc settings. The comment in this thread explains that, when importing pyplot, configure_inline_support is run
https://github.com/ipython/ipython/issues/12190#issuecomment-598998361

... which, in turn, updates the rcParams
https://github.com/ipython/ipython/blob/master/IPython/core/pylabtools.py#L399

... such as font.size
https://github.com/ipython/ipykernel/blob/master/ipykernel/pylab/config.py#L50

Was this page helpful?
0 / 5 - 0 ratings