JupyterLab is an awesome way of combining text and code in the same framework. This is a short guide on how to use JupyterLab. If you haven’t seen JupyterLab before it looks like this:

1. Starting JupyterLab

[For installation of JupyterLab see step 1b here]

  1. Open the program Terminal (Mac) or Anaconda Prompt (Windows)
  2. Paste in jupyter lab + Enter

Hopefully, you will experience that you browser automatically opens a new tab looking something like this:

2. Creating a notebook

In the Launcher tab you create a new Jupyter notebook by pressing the Python 3 bottom under Notebook. Notebooks consists of two types of cells:

  1. Code cells with Python code
  2. Markdown cells with text (see the guide Writing markdown)

When inside a cell you are in edit mode, when not you are in command mode.

The most important notebook commands are:

  • Movements: Arrows and scrolling
  • Run cell and advance: Shift+Enter
  • Run cell: Ctrl+Enter
  • Enter edit mode: Enter
  • Enter command mode: Ctrl+M
  • Change to markdown cell: M (only in command mode)
  • Change to code cell: Y (only in command mode)

In the left-panel on JupyterLab you can e.g. access:

  1. File Browser: To open existing notebooks anywhere on your computer.
  2. Running Terminals and Kernels: To shutdown terminals and kernels.
  3. Command Palette: To see a list of possible commands.
  4. Table of Contents: To see links to sections based on headings (#, ##, ###).

The interface of JupyterLab is explained in detail here.

The use of Jupyter notebooks in JupyterLab is explained in detail here.

3. Variable inspector

A very nice feature of JupyterLab is that it has a variable inspector that visualize vectors, DataFrames and matrices. You can open it by right-clicking in a notebook and choose “Open Variable Inspector”. It looks like this:

4. Shortcuts

Other good-to-know standard short-cuts are:

  • Only in command mode:
    • Create new cell above: A
    • Create new cell below: B
    • Cut cell: X
    • Copy cell: C
    • Paste cell: V
    • Delete cell: D+D
    • Toggle sidebar: Ctrl+B
    • Restart kernel: 0+0
  • Single-document mode: Ctrl+Shift+D
  • Autocomplete (when writing code): Tab
  • Show tooltip: Shift+Tab (used when inside function)

Advanced: Additionally, you can create customized short-cuts. Open settings with Ctrl+,. In the User Overrides tab paste in the followng:

{
    "runmenu:restart-and-run-all": {
      "selector": "[data-jp-code-runner]",        
      "command": "runmenu:restart-and-run-all",
      "keys": [
        "Ctrl Space"
      ]
    },     
    "notebook:move-cell-up": {
      "selector": ".jp-Notebook:focus",
      "command": "notebook:move-cell-up",
      "keys": [
        "Ctrl ArrowUp"
      ]
    },
    "notebook:move-cell-down": {
      "selector": ".jp-Notebook:focus",
      "command": "notebook:move-cell-down",
      "keys": [
        "Ctrl ArrowDown"
      ]
    }, 
    "application:toggle-presentation-mode": {
      "selector": "body",
      "command": "application:toggle-presentation-mode",
      "keys": [
        "Ctrl Shift P"
      ]
    }, 
    "notebook:line-numbering": {
      "selector": ".jp-Notebook.jp-mod-commandMode",        
      "command": "viewmenu:line-numbering",
      "keys": [
        "Ctrl Shift K"
      ]
    }    
}

You now have access to the following short-cuts:

  1. Restart kernal and run all cells: Ctrl+Space
  2. Toggle presentation mode: Ctrl+Shift+P
  3. Toggle line numbers: Ctrl+Shift+K
  4. Move cell up: Ctrl+ (only in command mode)
  5. Move cell down: Ctrl+ (only in command mode)

Next guide

Running Python in VSCode