Spec-Zone.ru › Octave 9

Предыдущая: Публикация разметки, Вверх: Файлы скриптов [Содержание][Индекс]

11.11.3 Jupyter Notebooks ¶

Jupyter notebooks — это популярный метод отображения кода, текста и графического вывода вместе в комплексной форме. Octave может публиковать результаты в Jupyter notebook с помощью функции jupyter_notebook.

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

Запустить и заполнить Jupyter Notebook в файле notebook_filename изнутри GNU Octave.

Поддерживаются как текстовые, так и графические выводы Octave.

Этот класс имеет общедоступное свойство notebook, которое представляет собой структуру, декодированную из JSON-данных Jupyter Notebook. Это свойство намеренно общедоступно для возможности расширенных манипуляций с notebook.

Примечание: версии Jupyter Notebook (nbformat) ниже 4.0 не поддерживаются.

Необязательный второй аргумент options — это структура с полями:

  • tmpdir для установки временной рабочей директории.

%plot магия поддерживается со следующими настройками:

  • "%plot -f <format>" или "%plot --format <format>": определяет формат хранения изображений. Поддерживаемые форматы:
    • PNG (по умолчанию)
    • SVG (Примечание: если изображения SVG не отображаются в notebook, скорее всего, это связано с механизмами безопасности Jupyter Notebook, и для их корректной работы потребуется явное «доверие» к ним).
    • JPG
  • "%plot -r <number>" или "%plot --resolution <number>": определяет разрешение изображения.
  • "%plot -w <number>" или "%plot --width <number>": определяет ширину изображения.
  • "%plot -h <number>" или "%plot --height <number>": определяет высоту изображения.

Примеры:

## 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");

См. также: jsondecode, jsonencode.

Предыдущая: Публикация разметки, Вверх: Файлы скриптов [Содержание][Индекс]

© 1996–2023 The Octave Project Developers
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions.
https://docs.octave.org/v9.2.0/Jupyter-Notebooks.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API