17

I want the effect of

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
%config InlineBackend.figure_format='retina'

at the launch of all my Jupyter notebooks, but I can't figure out what the current approach is for accomplishing this. There are many answers here and elsewhere, but none that I can find seem to be up to date.

How do I accomplish the above in the current versions of Jupyter notebooks (but not IPython generally!): what settings should I apply where is the configuration file I should put them in?


I've tried

c.InteractiveShellApp.matplotlib = "inline"
c.InlineBackend.figure_formats = set(['retina'])

in

~/.jupyter/jupyter_notebook_config.py

but this has no effect.

4
  • I think you want an IPython startup file: ipython.readthedocs.org/en/stable/interactive/… Commented Apr 1, 2016 at 16:36
  • @ThomasK: Does that apply to all of IPython, or just (as desired) to Jupyter notebooks? What do I put there? Commented Apr 1, 2016 at 16:39
  • Startup files apply to IPython however it's started. You put the code you want to run in them. Commented Apr 1, 2016 at 16:40
  • @So how does this address the question? What code goes where for Jupyter notebooks (only)? Commented Apr 1, 2016 at 16:46

1 Answer 1

7

I have

c.IPKernelApp.matplotlib = 'inline'
c.InlineBackend.figure_format = 'retina'

in my ~/.ipython/profile_default/ipython_kernel_config.py.

Sign up to request clarification or add additional context in comments.

6 Comments

Any idea what the relationship is between ipython_kernel_config.py (which I don't have) and ipython_notebook_config.py (which I do have, but), where these settings seem to have no effect.
You should have ipython_kernel_config.py in your ~/.ipython/profile_default/. Can you please run ipython profile create in your terminal. That should create all the config files. Make sure the lines you wish to take effect are uncommented and that the first uncommented line reads c = get_config().
That seems to work. But what are the roles now of other files like ipython_notebook_config.py (where I set my NotebookManager configuration) and ipython_config.py where I (try to) set my prompt and (successfully, I think) set InteractiveShellApp.exec_lines? Which get used by what (e.g., notebook vs shell) and which are obsolete? Is this documented anywhere?
Glad it worked. I am not entirely sure. You could read all about it here: ipython.readthedocs.io/en/stable/config/intro.html
As of today, I'm suddenly getting ValueError: could not convert string to float: figurefigure when I try to display a figure. This goes away when I remove c.InlineBackend.figure_format = 'retina' from my ipython_kernel_config.py.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.