3

Is it possible embed pictures into docstring in Python?

I saw docpicture keyword somewhere, but can't find doc on it. Is it stabdartized or not?

Where does picture should located?

UPDATE

I tried Sphinx notation, but my PyCharm shows

enter image description here

i.e. it sees that it should be an image here, but doesn't see image file.

Where I would put if used Sphinx?

Dims
  • 47,675
  • 117
  • 331
  • 600
  • 2
    Are you able to see the image in pycharm after placing the image at an appropriate location? For me, the image is rendered only when I enter the full path in "file:///Users/xyz/rotation_matrix.png" format. Relative paths are not working for me. – dips Nov 03 '18 at 17:07

1 Answers1

6

That depends on what tool you use for processing your docstring. Check your tool's documentation to find out how to embed images.

For example, if you are using Sphinx, you can use the image directive, as described in this StackOverflow answer:

.. image:: example.png

Regarding the location of the image, the documentation states:

When used within Sphinx, the file name given [...] must either be relative to the source file, or absolute which means that they are relative to the top source directory. For example, the file sketch/spam.rst could refer to the image images/spam.png as ../images/spam.png or /images/spam.png.

Felk
  • 7,720
  • 2
  • 35
  • 65
  • I am using pycharm and not generating documentation at all. I would like to see it while code exploring. What tool is most common? – Dims Aug 17 '17 at 15:45
  • I believe PyCharm supports Sphinx docstring syntax. Not sure if it would render images though – Felk Aug 17 '17 at 15:47
  • 1
    I found that PyCharm understands Sphinx notation. Hence the remaining part of the question is where image file should be located? – Dims Aug 17 '17 at 15:48
  • This helps and works for me. I like using absolute path `/path/to/image.png`, where leading `/` represents the path of the source folder. – panc Jun 24 '22 at 21:41