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–2022 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/v7.2.0/Jupyter-Notebooks.html