python - 如何在 Jupyter 中将图表图像导出为 pdf?

标签 python jupyter-notebook jupyter

我不想将整个笔记本导出为 pdf - 我已经搜索并找到了该问题的解决方案。我只想将笔记本中的绘图导出为 pdf 格式。有没有Python库可以做到这一点?

最佳答案

Jupyter nbconvert命令允许指定自定义模板。

Michael Goerz在这里为 LaTeX/PDF 编写了完整的自定义模板: https://gist.github.com/goerz/d5019bedacf5956bcf03ca8683dc5217

要仅打印图表,您可以修改它以清空输出单元格以外的任何部分,如下所示:

% Tell the templating engine what output template we want to use.
((* extends 'article.tplx' *))

% Template will setup imports, etc. as normal unless we override these sections.

% Leave title blank
((* block title -*))
((*- endblock title *))

% Leave author blank
((* block author -*))
((* endblock author *))

% Etc.
((* block maketitle *))
((* endblock maketitle *))

% Don't show "input" prompt
((*- block in_prompt -*))
((*- endblock in_prompt -*))

% Hide input cells
((*- block input -*))
((*- endblock input -*))

% Don't show "output" prompt
((*- block output_prompt -*))
((*- endblock output_prompt -*))

% Let template render output cells as usual

要生成 LaTeX 文件,请将以上内容另存为 custom_article.tplx 并运行:

jupyter nbconvert --to=latex --template=custom_article.tplx file.ipynb

要在单个命令中生成 LaTeX 文件和 PDF:

jupyter nbconvert --to=pdf --template=custom_article.tplx file.ipynb

关于python - 如何在 Jupyter 中将图表图像导出为 pdf?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61132129/

相关文章:

python - 在 Jupyter 中使用浏览按钮上传文件并使用/保存它们

jupyter-notebook - 无法显示类型为 HBox 的 Jupyter Widget;小部件 JavaScript 库丢失?

c++ - 如何在没有 Anaconda 的情况下安装 Xeus-cling?

Python - 有多少只是列表中的一个单词

python : imported packages with 'nested' modules

python - 如何清除使用 Keras 和 Tensorflow(作为后端)创建的模型?

python - 如何通过删除输出和转换来对 .ipynb 进行版本控制?

python - 在 Fedora Linux 上的 Jupyter 中运行 Python 2 和 3

python - Python UDP套接字在recvfrom()上引发立即错误

Python模糊匹配按类别分组