Ipython Notebook: Default Initialization Python Code

nick_name

I use iPython Notebook for scientific applications and I'm always plotting experimental data sets. The default image rendering and color cycling behavior of the combination of iPython Notebook and Matplotlib is pretty bad, but it's great after the following tweaks.

# ipython notebook specific
%pylab inline

# imports
from matplotlib import pyplot as plt
import matplotlib as mpl
from seaborn.apionly import set_palette
from IPython.display import set_matplotlib_formats

# configure plotting
set_matplotlib_formats('pdf', 'svg')
set_palette('Set1', n_colors=15, desat=None)
mpl.rcParams['figure.figsize']=(12.0,2.0)

I don't want to have to enter these manually in every notebook. How can I have these executed for all notebooks I'll ever create?

shadanan

You can create Python files in $HOME/.ipython/profile_default/startup/ that contains the code you want executed at startup.

For example, you can create $HOME/.ipython/profile_default/startup/00-init.py:

# imports
from matplotlib import pyplot as plt
import matplotlib as mpl
from seaborn.apionly import set_palette
from IPython.display import set_matplotlib_formats

# configure plotting
set_matplotlib_formats('pdf', 'svg')
set_palette('Set1', n_colors=15, desat=None)
mpl.rcParams['figure.figsize']=(12.0,2.0)

Note that IPython magics are not supported here, so %matplotlib inline won't work. This question deals with making %matplotlib inline the default.

You should be aware that if you change the defaults for your IPython environment, your notebooks may not work on other people's IPython installations.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Ipython notebook - Create a new notebook (Python conda or default Python)

From Dev

Default notebook directory in iPython Notebook - iPython 3.0.0

From Dev

How to display line numbers in IPython Notebook code cell by default

From Dev

Where are python logs default stored when ran through IPython notebook?

From Dev

iPython Notebook svg Figures by Default

From Dev

Best way to run Julia code in an IPython notebook (or Python code in an IJulia notebook)

From Dev

Closed IPython Notebook that was running code

From Dev

Closed IPython Notebook that was running code

From Dev

Default template for iPython notebook (using Jupyter)

From Dev

How to change default colour scheme for ipython notebook?

From Dev

ipython notebook: how to toggle header invisible by default

From Dev

Changing the default port for iPython notebook server / Jupyter

From Dev

IPython/Jupyter notebook 3 - hide headers by default

From Dev

Verifying PEP8 in iPython notebook code

From Dev

ipython notebook clear cell output in code

From Dev

Is there a way to run scala code in the ipython notebook?

From Dev

Jump to next code cell (IPython notebook)

From Dev

How to activate the code assistance in IPython Notebook / Jupyter

From Dev

How to use python-defined variables in javascript code within ipython notebook?

From Dev

Interactive plots in Jupyter (IPython) notebook with draggable points that call Python code when dragged

From Dev

Jupyter (ipython notebook), hide menu and some toolbar buttons, or run python code on loading

From Dev

Execute IPython notebook cell from python script

From Dev

Python dictionary as html table in ipython notebook

From Dev

ipython notebook R cell magic as a python function

From Dev

IPython Notebook in a virtualenv, using Python 3.3

From Dev

Anaconda: Python 3 and 2 in IPython/Jupyter Notebook

From Dev

Python Bloomberg API not connecting from ipython notebook

From Dev

Python Bloomberg API not connecting from ipython notebook

From Dev

How to change the default browser used by the ipython/jupyter notebook in Linux?

Related Related

  1. 1

    Ipython notebook - Create a new notebook (Python conda or default Python)

  2. 2

    Default notebook directory in iPython Notebook - iPython 3.0.0

  3. 3

    How to display line numbers in IPython Notebook code cell by default

  4. 4

    Where are python logs default stored when ran through IPython notebook?

  5. 5

    iPython Notebook svg Figures by Default

  6. 6

    Best way to run Julia code in an IPython notebook (or Python code in an IJulia notebook)

  7. 7

    Closed IPython Notebook that was running code

  8. 8

    Closed IPython Notebook that was running code

  9. 9

    Default template for iPython notebook (using Jupyter)

  10. 10

    How to change default colour scheme for ipython notebook?

  11. 11

    ipython notebook: how to toggle header invisible by default

  12. 12

    Changing the default port for iPython notebook server / Jupyter

  13. 13

    IPython/Jupyter notebook 3 - hide headers by default

  14. 14

    Verifying PEP8 in iPython notebook code

  15. 15

    ipython notebook clear cell output in code

  16. 16

    Is there a way to run scala code in the ipython notebook?

  17. 17

    Jump to next code cell (IPython notebook)

  18. 18

    How to activate the code assistance in IPython Notebook / Jupyter

  19. 19

    How to use python-defined variables in javascript code within ipython notebook?

  20. 20

    Interactive plots in Jupyter (IPython) notebook with draggable points that call Python code when dragged

  21. 21

    Jupyter (ipython notebook), hide menu and some toolbar buttons, or run python code on loading

  22. 22

    Execute IPython notebook cell from python script

  23. 23

    Python dictionary as html table in ipython notebook

  24. 24

    ipython notebook R cell magic as a python function

  25. 25

    IPython Notebook in a virtualenv, using Python 3.3

  26. 26

    Anaconda: Python 3 and 2 in IPython/Jupyter Notebook

  27. 27

    Python Bloomberg API not connecting from ipython notebook

  28. 28

    Python Bloomberg API not connecting from ipython notebook

  29. 29

    How to change the default browser used by the ipython/jupyter notebook in Linux?

HotTag

Archive