python - 在 Sphinx : how to show documentation 中嵌入 matplotlib 图

标签 python matplotlib ipython python-sphinx

我有一些 ipynb 文档,其中包含由 %matplotlib inline 指令内联显示的 matplotlib 图。

当我尝试用内联绘图显示我的笔记本时,我有我的 Sphinx 文档。我尝试使用

ipython nbconvert shalom.ipynb --to rst

但是,遗憾的是,它确实给了我一个没有任何内联图形的 RST。只有代码 list 。

你能告诉我如何使用已渲染的图生成 Sphinx 文档吗。

我知道这是可能的。

最佳答案

您需要使用 Sphinx extensions for embedded plots, math and more

Sphinx is written in python, and supports the ability to write custom extensions. We’ve written a few for the matplotlib documentation, some of which are part of matplotlib itself in the matplotlib.sphinxext module, some of which are included only in the sphinx doc directory, and there are other extensions written by other groups, eg numpy and ipython. We’re collecting these in this tutorial and showing you how to install and use them for your own project. First let’s grab the python extension files from the sphinxext directory from git (see Fetching the data), and install them in our sampledoc project sphinxext directory:

您需要修改您的 conf.py 以包括:

extensions = [
          'matplotlib.sphinxext.mathmpl',
          'matplotlib.sphinxext.only_directives',
          'matplotlib.sphinxext.plot_directive',
          'matplotlib.sphinxext.ipython_directive',
          'sphinx.ext.autodoc',
          'sphinx.ext.doctest',
          'ipython_console_highlighting',
          'inheritance_diagram',
          'numpydoc']

关于python - 在 Sphinx : how to show documentation 中嵌入 matplotlib 图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30397384/

相关文章:

python - Pyplot 无法绘制回归

python - 为 pandas/matplotlib 设置 xlim,其中索引为字符串

python - 用 Python 读取数千个 JSON 文件的最快方法

python - Django 管理命令无法返回字典

python - 如何检查字符串列表中是否存在子字符串

python - 循环两个不同的 Pandas Dataframes

python - conda 卡在 Proceed ([y]/n) 上?在 ipython 控制台中更新软件包时

带有 unicode 和标点符号的 Javascript 正则表达式

python - 在 matplotlib 中将一个图像动画化到另一个图像之上

python - 被变量遮盖的 ipdb 命令