Customizing IPython Notebook

| Comments

IPhython notebook is a very popular platform for coding and sharing projects in Python. Only recently I found a lot of official and unofficial extensions for improving its usability. Among them, I installed the following:

  1. Comment-uncomment: this extension creates the shortcut alt+C for commenting code blocks (in the case you have a not-American keyboard and the standard (cmd|ctrl)-/ doesn’t work)
  2. Theme toggle: it creates a shortcut for toogle the css theme (I chose the ocean dark one).
  3. Notify: tired of checking if the kernel is still busy? This extension enables custom browser notifications for when the kernel becomes finally idle.
  4. Calico-spell-check: it creates a toolbar button for spell checking in the markdown cells.

Moreover, it’s possible to enable retina resolution on matplotlib graphs by changing the c.InlineBackend.figure_formats value in the iphyton notebook config file (usually in ~/.iphyton/profile_default/ipython_notebook_config.py), and remove the space-consuming header of the page by adding div#header {display: none !important;} to the custom.css file.

Final note: in order to work together, it’s important to load the extensions in the right oder. Here is how I load them in my custom.js file:

require(["base/js/events"], function (events) {
$([IPython.events]).on("app_initialized.NotebookApp", function () {
    IPython.load_extensions('comment-uncomment');
    IPython.load_extensions('theme_toggle');
    });
});

IPython.load_extensions('notify');
IPython.load_extensions('calico-spell-check');

require(["nbextensions/theme_toggle"], function (theme_toggle) {
    $([IPython.events]).on("notebook_loaded.Notebook", theme_toggle.theme_toggle_shortcut);
});

Comments