@@ -20,12 +20,10 @@ the docstrings of the classes in the Matplotlib library. Except for
20
20
:file: `doc/api/api_changes/ `, ``.rst `` files in :file: `doc/api ` are created
21
21
when the documentation is built. See :ref: `writing-docstrings ` below.
22
22
23
- Second, the contents of :file: `doc/plot_types `, :file: `doc/gallery ` and
24
- :file: `doc/tutorials ` are generated by the `Sphinx Gallery `_ from python files
25
- in :file: `galleries/plot_types/ `, :file: `galleries/examples/ ` and
26
- :file: `galleries/tutorials/ `. These sources consist of python scripts that have
27
- ReST _ documentation built into their comments. See
28
- :ref: `writing-examples-and-tutorials ` below.
23
+ Second, our example pages, tutorials, and some of the narrative documentation
24
+ are created by `Sphinx Gallery `_. Sphinx Gallery converts example Python files
25
+ to ``*.rst `` files with the result of Matplotlib plot calls as embedded images.
26
+ See :ref: `writing-examples-and-tutorials ` below.
29
27
30
28
Third, Matplotlib has narrative docs written in ReST _ in subdirectories of
31
29
:file: `doc/users/ `. If you would like to add new documentation that is suited
@@ -818,11 +816,30 @@ code will also appear in interactive docstrings.
818
816
Writing examples and tutorials
819
817
==============================
820
818
821
- Examples and tutorials are python scripts that are run by `Sphinx Gallery `_
822
- to create a gallery of images in the :file: `/doc/gallery ` and
823
- :file: `/doc/tutorials ` directories respectively. To exclude an example
824
- from having an plot generated insert "sgskip" somewhere in the filename.
825
-
819
+ Examples and tutorials are Python scripts that are run by `Sphinx Gallery `_.
820
+ Sphinx Gallery finds ``*.py `` files in source directories and runs the files to
821
+ create images and narrative that are embedded in ``*.rst `` files in a build
822
+ location of the :file: `doc/ ` directory. Files in the build location should not
823
+ be directly edited as they will be overwritten by Sphinx gallery. Currently
824
+ Matplotlib has four galleries as follows:
825
+
826
+ =============================== ==========================
827
+ Source location Build location
828
+ =============================== ==========================
829
+ :file: `galleries/plot_types ` :file: `doc/plot_types `
830
+ :file: `galleries/examples ` :file: `doc/gallery `
831
+ :file: `galleries/tutorials ` :file: `doc/tutorials `
832
+ :file: `galleries/users_explain ` :file: `doc/users/explain `
833
+ =============================== ==========================
834
+
835
+ The first three are traditional galleries. The last,
836
+ :file: `galleries/users_explain `, is a mixed gallery where some of the files are
837
+ raw ``*.rst `` files and some are ``*.py `` files; Sphinx Gallery just copies
838
+ these ``*.rst `` files from the source location to the build location (see
839
+ :ref: `raw_restructured_gallery `, below).
840
+
841
+ In the Python files, to exclude an example from having a plot generated, insert
842
+ "sgskip" somewhere in the filename.
826
843
827
844
Formatting the example
828
845
----------------------
@@ -947,6 +964,23 @@ to name your example consistently, i.e. use the main function or subject
947
964
of the example as first word in the filename; e.g. an image example
948
965
should ideally be named similar to :file: `imshow_mynewexample.py `.
949
966
967
+ .. _raw_restructured_gallery :
968
+
969
+ Raw restructured text files in the gallery
970
+ ------------------------------------------
971
+
972
+ `Sphinx Gallery `_ folders usually consist of a ``README.txt `` and a series of
973
+ Python source files that are then translated to an ``index.rst `` file and a
974
+ series of ``example_name.rst `` files in the :file: `doc/ ` subdirectories.
975
+ However, Sphinx Gallery also allows raw ``*.rst `` files to be passed through a
976
+ gallery (see `Manually passing files `_ in the Sphinx Gallery documentation). We
977
+ use this feature in :file: `galleries/users_explain `, where, for instance,
978
+ :file: `galleries/users_explain/colors ` is a regular Sphinx Gallery
979
+ subdirectory, but :file: `galleries/users_explain/artists ` has a mix of
980
+ ``*.rst `` and ``*py `` files. For mixed subdirectories like this, we must add
981
+ any ``*.rst `` files to a ``:toctree: ``, either in the ``README.txt `` or in a
982
+ manual ``index.rst ``.
983
+
950
984
Miscellaneous
951
985
=============
952
986
@@ -1022,3 +1056,4 @@ style or topbar should be made there to propagate across all subprojects.
1022
1056
.. _`Sphinx Gallery` : https://sphinx-gallery.readthedocs.io/en/latest/
1023
1057
.. _references : https://www.sphinx-doc.org/en/stable/usage/restructuredtext/roles.html
1024
1058
.. _`numpydoc docstring guide` : https://numpydoc.readthedocs.io/en/latest/format.html
1059
+ .. _`Manually passing files` : https://sphinx-gallery.github.io/stable/configuration.html#manually-passing-files
0 commit comments