vin*_*ega 5 python matplotlib jupyter-notebook jupyter-contrib-nbextensions
我已经构建了一个笔记本用于可视化目的。
首先,我使用以下命令行界面将其导出为 html nbconvert:
jupyter nbconvert myNotebook.ipynb --no-input添加--no-input标志以隐藏输入单元格
输出由带有嵌入图的单个 html 文件组成。正如预期的那样
其次,为了向我的报告添加目录,我还安装了该jupyter_contrib_nbextensions软件包。
我使用目录 (2)包。但是,当我将笔记本导出为 HTML 时,
jupyter nbconvert myNotebook.ipynb --no-input --to html_toc
绘图现在保存在单独的文件夹中
我想将它们嵌入到 html 文件中。有人知道如何解决这个问题吗?
这里有一个简单的笔记本可以用来说明问题
#%%
import numpy as np
import matplotlib.pyplot as plt
#%% md
# Linear plot with noise
#%%
x = np.linspace(0, 10, 100)
noise = np.random.randn(len(x))
y1 = 2 * x + noise
plt.plot(x, y1);
#%% md
# Sine plot with noise
#%%
y2 = 5 * np.sin(x) + noise
plt.plot(x, y2);
Run Code Online (Sandbox Code Playgroud)
小智 1
toc2 使用额外的预处理器 ExtractOutputPreprocessor
创建一个nbconvert_config.py包含以下内容的文件:
c = get_config()
c.NbConvertApp.notebooks = ['mynotebook.ipynb']
c.NbConvertApp.export_format = 'html_toc'
c.Exporter.preprocessors = [
'nbconvert.preprocessors.TagRemovePreprocessor',
'nbconvert.preprocessors.RegexRemovePreprocessor',
'nbconvert.preprocessors.coalesce_streams',
'nbconvert.preprocessors.CSSHTMLHeaderPreprocessor',
'nbconvert.preprocessors.HighlightMagicsPreprocessor',
#'nbconvert.preprocessors.ExtractOutputPreprocessor',
]
Run Code Online (Sandbox Code Playgroud)
并致电jupyter nbconvert --config nbconvert_config.py. 关键是列表中必须注释的最后一个条目。
| 归档时间: |
|
| 查看次数: |
3989 次 |
| 最近记录: |