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.

orome
  • 45,163
  • 57
  • 202
  • 418
  • I think you want an IPython startup file: http://ipython.readthedocs.org/en/stable/interactive/tutorial.html#startup-files – Thomas K Apr 01 '16 at 16:36
  • @ThomasK: Does that apply to all of IPython, or just (as desired) to Jupyter notebooks? What do I put there? – orome Apr 01 '16 at 16:39
  • Startup files apply to IPython however it's started. You put the code you want to run in them. – Thomas K Apr 01 '16 at 16:40
  • @So how does this address the question? What code goes where for Jupyter notebooks (only)? – orome Apr 01 '16 at 16:46

1 Answers1

7

I have

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

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

Shahar
  • 886
  • 1
  • 10
  • 22
  • 1
    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. – orome Jan 20 '17 at 13:20
  • 2
    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()`. – Shahar Jan 22 '17 at 08:51
  • 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](http://stackoverflow.com/q/38361607/656912)) 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*? – orome Jan 22 '17 at 13:27
  • Glad it worked. I am not entirely sure. You could read all about it here: http://ipython.readthedocs.io/en/stable/config/intro.html – Shahar Jan 23 '17 at 11:26
  • 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`. – ijoseph Apr 17 '19 at 20:55
  • Update: went away when I updated from `ipython` 4.0.0 to 5.8.0. – ijoseph Apr 17 '19 at 21:00