-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Open
Description
Problem
In the sphinx extension, the :context:
makes it possible to reuse code accross calls.
However, this does not seem to work across different docstrings. So if one wants to document each method of a class with a plot, you have to re-instantiate the class every time.
Using the global plot_pre_code
config option is not really manageable outside of a small project.
Proposed solution
option A
Make it so that the context persists across docstrings. But I'm not sure sphinx allows that.
class Whatever:
"""The Whatever class
.. plot::
:context:
:nofigs:
w = Whatever()
"""
def a(self):
"""the a method.
.. plot::
:context:
plt.figure()
plt.scatter(*w.a())
"""
return [(0., 1.), (0., 1.)]
def b(self):
"""the b method.
.. plot::
:context:
plt.figure()
plt.scatter(*w.b())
"""
return [(0., 1.), (0., 1.)]
option B
Add a .. plotsetup::
directive similar to the doctest testsetup
directive. That way, one might be able to write:
class Whatever:
"""The Whatever class
.. plotsetup::
w = Whatever()
"""
def a(self):
"""the a method.
.. plot::
plt.figure()
plt.scatter(*w.a())
"""
return [(0., 1.), (0., 1.)]
def b(self):
"""the b method.
.. plot::
plt.figure()
plt.scatter(*w.b())
"""
return [(0., 1.), (0., 1.)]