In the first cell of every iPython (Jupyter) notebook, I almost always type:
%matplotlib inline import matplotlib.pyplot as plt import numpy as np
Is there a way to make it so that this cell appears at the top of each new notebook I create by default?
For example, could I save a template .ipynb
file somewhere, which is copied by iPython when creating a new notebook?
(I found this question, but it seems to be more about css than default content in cells.)
Configuration files Config files are stored by default in the ~/. jupyter directory.
The IPython Notebook is now known as the Jupyter Notebook. It is an interactive computational environment, in which you can combine code execution, rich text, mathematics, plots and rich media. For more details on the Jupyter Notebook, please see the Jupyter website.
The name, Jupyter, comes from the core supported programming languages that it supports: Julia, Python, and R. Jupyter ships with the IPython kernel, which allows you to write your programs in Python, but there are currently over 100 other kernels that you can also use.
I know it may not be what you're looking for (this example is not good for working on notebooks that need to be run in multiple environments, e.g. shared), but I put the following in a file called ipython_config.py
in my .ipython
folder.
c.InteractiveShellApp.exec_lines = ['%matplotlib inline', 'import numpy as np', 'import scipy.constants as scc', 'import scipy.integrate as sci', 'from mpl_toolkits.mplot3d import Axes3D', 'import scipy.optimize as sco' ]
This runs before anything runs in any interactive console, including the jupyter notebook. If you want explicit boilerplating, I think that you will be disappointed (unless you want to build in the functionality for us ☺)
There is a pretty cool solution using jupyterlab: jupyterlab_templates
Installation took about 5 minutes and you can have as many
templates as you'd like.
Assuming you have conda installed than during the installation, you'll need to install node js engine:
conda install -c conda-forge nodejs
And create a jupter_noteook_config.py if you don't have one :
jupyter notebook --generate-config
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With