Jupyter Notebooks (GNU Octave (version 8.0.90))

Previous: Publishing Markup, Up: Script Files [Contents][Index]

#### 11.11.3 Jupyter Notebooks

Jupyter notebooks are one popular technique for displaying code, text, and graphical output together in a comprehensive manner. Octave can publish results to a Jupyter notebook with the function `jupyter_notebook`.

: notebook = jupyter_notebook (notebook_filename) ¶
: notebook = jupyter_notebook (notebook_filename, options) ¶

  Run and fill the Jupyter Notebook in file notebook_filename from within GNU Octave.

  Both text and graphical Octave outputs are supported.

  This class has a public property `notebook` which is a structure representing the JSON-decoded Jupyter Notebook. This property is intentionally public to enable advanced notebook manipulations.

  Note: Jupyter Notebook versions (`nbformat`) lower than 4.0 are not supported.

  The optional second argument options is a struct with fields:

  - `tmpdir` to set the temporary working directory.

  `%plot` magic is supported with the following settings:

  - "%plot -f <format>" or "%plot –format <format>": specifies the image storage format. Supported formats are:
    - - PNG (default)
    - - SVG (Note: If SVG images do not appear in the notebook, it is most likely related to Jupyter Notebook security mechanisms and explicitly "trusting" them will be necessary).
    - - JPG
  - "%plot -r <number>" or "%plot –resolution <number>": specifies the image resolution.
  - "%plot -w <number>" or "%plot –width <number>": specifies the image width.
  - "%plot -h <number>" or "%plot –height <number>": specifies the image height.

  Examples:

      ## Run all cells and generate the filled notebook

      ## Instantiate an object from a notebook file
      notebook = jupyter_notebook ("myNotebook.ipynb");
      ## Run the code and embed the results in the notebook property
      notebook.run_all ();
      ## Generate a new notebook by overwriting the original notebook
      notebook.generate_notebook ("myNotebook.ipynb");

      ## Run just the second cell and generate the filled notebook

      ## Instantiate an object from a notebook file
      notebook = jupyter_notebook ("myNotebook.ipynb");
      ## Run the code and embed the results in the notebook property
      notebook.run (2)
      ## Generate a new notebook in a new file
      notebook.generate_notebook ("myNewNotebook.ipynb");

      ## Generate an Octave script from a notebook

      ## Instantiate an object from a notebook file
      notebook = jupyter_notebook ("myNotebook.ipynb");
      ## Generate the Octave script
      notebook.generate_octave_script ("jup_script.m");

  See also: jsondecode, jsonencode.

Previous: Publishing Markup, Up: Script Files [Contents][Index]