2

Is there a way to incorporate the .. plot:: directive in Sphinx with the .. testcode:: one?

When using doctest type I can integrate them like (just general idea):

>>> import matplotlib.pyplot as plt
>>> import numpy as np

>>> x = np.array([0,1,2])

.. plot::
    plt(x)
    plt.show()

>>> print(x)
[0,1,2]

Then a figure would be inserted above the example output. Instead of using the >>>, can one do something more like:

.. testcode:: *
    import matplotlib.pyplot as plt
    import numpy as np
    
    x = np.array([0,1,2])

.. plot::
    plt(x)
    plt.show()

.. testcode:: *
    print(x)

.. testoutput:: *
[0,1,2]

When I try something like the one above, the plot directive does not have access to x, and doesn't seem to allow the groups option.

001001
  • 530
  • 1
  • 4
  • 13

0 Answers0