Skip to content

Commit 5b7f8e7

Browse files
DOC: use minigallery for tutorial thumbnails (#31275)
This simplifies the reST by removing several manually-written HTML raw blocks. Co-authored-by: hannah <story645@gmail.com>
1 parent 87ea4e4 commit 5b7f8e7

File tree

3 files changed

+15
-96
lines changed

3 files changed

+15
-96
lines changed

doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ def autodoc_process_bases(app, name, obj, options, bases):
292292

293293
sphinx_gallery_conf = {
294294
'backreferences_dir': Path('api', '_as_gen'),
295+
'minigallery_sort_order': 'sphinxext.gallery_order.preserve_order',
295296
# Compression is a significant effort that we skip for local and CI builds.
296297
'compress_images': ('thumbnails', 'images') if is_release_build else (),
297298
'doc_module': ('matplotlib', 'mpl_toolkits'),

doc/sphinxext/gallery_order.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Paths are relative to the conf.py file.
44
"""
55

6+
import itertools
67
from sphinx_gallery.sorting import ExplicitOrder
78

89
# Gallery sections shall be displayed in the following order.
@@ -127,3 +128,10 @@ def __call__(self, item):
127128
# Provide the above classes for use in conf.py
128129
sectionorder = MplExplicitOrder(explicit_order_folders)
129130
subsectionorder = MplExplicitSubOrder
131+
132+
_preserve_count = itertools.count()
133+
134+
135+
def preserve_order(item):
136+
"""A sorting key to preserve the original order of items in minigalleries."""
137+
return next(_preserve_count)

galleries/tutorials/index.rst

Lines changed: 6 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -9,101 +9,12 @@ For shorter examples, see our :ref:`examples page <examples-index>`.
99
You can also find :ref:`external resources <resources-index>` and
1010
a :ref:`FAQ <howto-faq>` in our :ref:`user guide <users-guide-index>`.
1111

12-
13-
.. raw:: html
14-
15-
<div class="sphx-glr-thumbnails">
16-
17-
18-
.. raw:: html
19-
20-
<div class="sphx-glr-thumbcontainer" tooltip="An introduction to the pyplot interface. Please also see quick_start for an overview of how Ma...">
21-
22-
.. only:: html
23-
24-
.. image:: /tutorials/images/thumb/sphx_glr_pyplot_thumb.png
25-
:alt: Pyplot tutorial
26-
27-
:ref:`sphx_glr_tutorials_pyplot.py`
28-
29-
.. raw:: html
30-
31-
<div class="sphx-glr-thumbnail-title">Pyplot tutorial</div>
32-
</div>
33-
34-
35-
.. raw:: html
36-
37-
<div class="sphx-glr-thumbcontainer" tooltip="Coding shortcuts">
38-
39-
.. only:: html
40-
41-
.. image:: /tutorials/images/thumb/sphx_glr_coding_shortcuts_thumb.png
42-
:alt: Coding shortcuts
43-
44-
:ref:`sphx_glr_tutorials_coding_shortcuts.py`
45-
46-
.. raw:: html
47-
48-
<div class="sphx-glr-thumbnail-title">Coding shortcuts</div>
49-
</div>
50-
51-
52-
.. raw:: html
53-
54-
<div class="sphx-glr-thumbcontainer" tooltip="A short tutorial on plotting images with Matplotlib.">
55-
56-
.. only:: html
57-
58-
.. image:: /tutorials/images/thumb/sphx_glr_images_thumb.png
59-
:alt: Image tutorial
60-
61-
:ref:`sphx_glr_tutorials_images.py`
62-
63-
.. raw:: html
64-
65-
<div class="sphx-glr-thumbnail-title">Image tutorial</div>
66-
</div>
67-
68-
69-
.. raw:: html
70-
71-
<div class="sphx-glr-thumbcontainer" tooltip="This tutorial aims to show the beginning, middle, and end of a single visualization using Matpl...">
72-
73-
.. only:: html
74-
75-
.. image:: /tutorials/images/thumb/sphx_glr_lifecycle_thumb.png
76-
:alt: The Lifecycle of a Plot
77-
78-
:ref:`sphx_glr_tutorials_lifecycle.py`
79-
80-
.. raw:: html
81-
82-
<div class="sphx-glr-thumbnail-title">The Lifecycle of a Plot</div>
83-
</div>
84-
85-
86-
.. raw:: html
87-
88-
<div class="sphx-glr-thumbcontainer" tooltip="Using Artist objects to render on the canvas.">
89-
90-
.. only:: html
91-
92-
.. image:: /tutorials/images/thumb/sphx_glr_artists_thumb.png
93-
:alt: Artist tutorial
94-
95-
:ref:`sphx_glr_tutorials_artists.py`
96-
97-
.. raw:: html
98-
99-
<div class="sphx-glr-thumbnail-title">Artist tutorial</div>
100-
</div>
101-
102-
103-
.. raw:: html
104-
105-
</div>
106-
12+
.. minigallery::
13+
../galleries/tutorials/pyplot.py
14+
../galleries/tutorials/coding_shortcuts.py
15+
../galleries/tutorials/images.py
16+
../galleries/tutorials/lifecycle.py
17+
../galleries/tutorials/artists.py
10718

10819
.. toctree::
10920
:hidden:
@@ -127,7 +38,6 @@ a :ref:`FAQ <howto-faq>` in our :ref:`user guide <users-guide-index>`.
12738
:download:`Download all examples in Jupyter notebooks: tutorials_jupyter.zip </tutorials/tutorials_jupyter.zip>`
12839

12940

130-
13141
.. _user_guide_tutorials:
13242

13343
User guide tutorials

0 commit comments

Comments
 (0)