我不想将整个笔记本导出为 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/