有没有一种方法可以在带有sphinx的plt.show()之后显示图,或在.. plot ::

问题描述 投票:0回答:1
我正在使用带有numpydocsdoctest和scipy主题的狮身人面像。

在文档字符串中使用.. plot::时,所有图均已创建,除了不显示调用位置外,所有图均移至文档末尾。有没有一种方法可以强制将其内联,而无需在.rst文件中重写示例?这是我的example.py文件docstring的样子:

.. plot:: >>> import numpy as np >>> import matplotlib.pylab as plt # commentary breaking the block Finished Imports >>> x = np.linspace(-np.pi*2, np.pi*2, 2000) >>> y = np.sin(x) >>> plt.plot(x, y)#doctest: +SKIP >>> plt.show()#doctest: +SKIP First plot should be here >>> x2 = x >>> plt.plot(x2, y)#doctest: +SKIP >>> plt.show()#doctest: +SKIP Second plot should be here

....

But both are here.

或者,我尝试添加另一个.. plot::方法,但是它改变了范围。

.. plot:: >>> import numpy as np >>> import matplotlib.pylab as plt # commentary breaking the block Finished Imports >>> x = np.linspace(-np.pi*2, np.pi*2, 2000) >>> y = np.sin(x) >>> plt.plot(x, y)#doctest: +SKIP >>> plt.show()#doctest: +SKIP First plot should be here .. plot:: >>> x2 = x >>> plt.plot(x2, y)#doctest: +SKIP >>> plt.show()#doctest: +SKIP

使用make html时哪个状态将不定义x
python-sphinx numpydoc
1个回答
0
投票
我遇到了两个问题,现在已解决。首先,我没有正确显示所有更新,因此我需要在make clean之前每次运行make html

解决原始问题的方法是,每次调用:context: close-figs时,在.. plot::之后添加plot.show()

.. plot:: :context: close-figs

所以我的文档字符串现在看起来像:

.. plot:: :context: close-figs >>> import numpy as np >>> import matplotlib.pylab as plt # commentary breaking the block Finished Imports >>> x = np.linspace(-np.pi*2, np.pi*2, 2000) >>> y = np.sin(x) >>> plt.plot(x, y)#doctest: +SKIP >>> plt.show()#doctest: +SKIP .. plot:: :context: close-figs First plot shows here >>> x2 = x >>> plt.plot(x2, y)#doctest: +SKIP >>> plt.show()#doctest: +SKIP .. plot:: :context: close-figs Second plot shows here

© www.soinside.com 2019 - 2024. All rights reserved.