numpydocs
,doctest
和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
。
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