Skip to content

DOC: use minigallery for tutorial thumbnails#31275

Open
MohitPal2005 wants to merge 15 commits intomatplotlib:mainfrom
MohitPal2005:fix-issue-name
Open

DOC: use minigallery for tutorial thumbnails#31275
MohitPal2005 wants to merge 15 commits intomatplotlib:mainfrom
MohitPal2005:fix-issue-name

Conversation

@MohitPal2005
Copy link

PR summary

This PR adds the sphinx_gallery_thumbnail_number directive to
galleries/tutorials/artists.py.

This ensures that Sphinx-Gallery selects the intended figure as the
thumbnail for the tutorial in the gallery.

Without this directive, the gallery may choose an unintended frame
or fail to generate a proper thumbnail.

Closes #17479

AI Disclosure

AI tools were used for guidance on Git workflow and understanding
the repository structure. The code change itself was written
and verified manually.

@github-actions
Copy link

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide.
Please let us know if (and how) you use AI, it will help us give you better feedback on your PR.

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@story645
Copy link
Member

story645 commented Mar 11, 2026

Thanks for the PR, but tutorials don't have thumbnails b/c of the way the index page is written for tutorials. The solution for tutorials is to use the sphinx minigallery directive to grab the tutorial files, which may include a reorg of the tutorials landing page.

@MohitPal2005
Copy link
Author

Thank you for the clarification!

I understand that tutorials use a different mechanism and that the correct
solution is to use the sphinx minigallery directive instead of
sphinx_gallery_thumbnail_number.

I will look into the tutorials landing page and explore how the
minigallery directive can be used to properly generate thumbnails.

Please let me know if there are specific files or examples I should start with.

@melissawm melissawm moved this to Waiting for author in First Time Contributors Mar 11, 2026
@story645 story645 marked this pull request as draft March 11, 2026 15:37
@story645 story645 marked this pull request as draft March 11, 2026 15:37
@MohitPal2005 MohitPal2005 marked this pull request as ready for review March 12, 2026 22:53
@MohitPal2005
Copy link
Author

Thank you for the guidance! I have removed the thumbnail variable from the Python script and successfully added the minigallery directive to the tutorial's index.rst landing page as requested.

@melissawm melissawm moved this from Waiting for author to Needs review in First Time Contributors Mar 13, 2026
@story645
Copy link
Member

This PR yields a page that looks exactly like the current tutorial landing page https://matplotlib.org/devdocs/tutorials/index.html

But also I don't think this is the right approach. I think if we were gonna add thumbnails to tutorials, the page should be restructured to use the minigallery directive to show thumbnails under each header.

@MohitPal2005
Copy link
Author

Hi @story645, thank you so much for the review and the architectural direction!

I completely agree that restructuring the page to use the minigallery directive under each specific header will make the tutorial landing page much more visually useful. I will pivot my approach, restructure the index.rst file as you suggested, and push an updated commit shortly.

@story645
Copy link
Member

story645 commented Mar 18, 2026

restructure the index.rst file

What is your plan here? Your comments concern me a bit b/c they're mirroring mine but not really engaging w/ the contents.

@MohitPal2005
Copy link
Author

Thanks for pointing that out — that’s helpful.

Here’s what I’m thinking for the page:

  • I’ll split the tutorials into sections based on how they’re already grouped (like more introductory vs more specific topics), instead of keeping everything in one list.
  • Under each section, I’ll add a .. minigallery:: so each group shows its own thumbnails.
  • I’ll keep the existing toctree (probably hidden) so navigation doesn’t break, but the visible page will be driven by these section-wise galleries.

So the idea is not just adding thumbnails, but actually changing how the page is structured.

I’ll try this locally and push an update so we can see how it looks.

@melissawm melissawm moved this from Needs review to Waiting for author in First Time Contributors Mar 18, 2026
@story645 story645 marked this pull request as draft March 18, 2026 15:20
@story645
Copy link
Member

putting to draft until the docs build well enough to show the proposal - also please update the PR title to what this PR is doing now.

@MohitPal2005 MohitPal2005 marked this pull request as ready for review March 18, 2026 20:40
@story645
Copy link
Member

story645 commented Mar 18, 2026

I think this needs some feedback from other maintainers too, but I think using the sphinx gallery machinery is an improvement over hardcoding the html:
https://output.circle-artifacts.com/output/job/d6c63851-f51d-42ef-ab79-3b17f7f68e21/artifacts/0/doc/build/html/tutorials/index.html

image

@story645 story645 added the status: needs comment/discussion needs consensus on next step label Mar 18, 2026
@story645 story645 changed the title DOC: Add sphinx_gallery_thumbnail_number to artists tutorial DOC: use minigallery for tutorial thumbnails Mar 18, 2026

.. image:: /tutorials/images/thumb/sphx_glr_artists_thumb.png
:alt: Artist tutorial
.. minigallery::
Copy link
Member

@story645 story645 Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's going to default sort by file name, to keep the original given order you probably can use ExplicitOrder (not totally sure)

https://sphinx-gallery.github.io/stable/configuration.html#sort-mini-gallery-thumbnails-from-files

@MohitPal2005
Copy link
Author

Thanks for the approval and the suggestion!

I’ve looked into the ordering and updated the minigallery to better match the original tutorial order while keeping the changes minimal.

Let me know if you’d prefer a different approach.

Comment on lines +17 to +19
../galleries/tutorials/pyplot.py
../galleries/tutorials/coding_shortcuts.py
../galleries/tutorials/images.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you look at the output from this PR, you'll see that this doesn't affect the output:

Image

Sphinx gallery instructions for configuring sorting are at https://sphinx-gallery.github.io/stable/configuration.html#sort-mini-gallery-thumbnails-from-files & you probably want to configure minigallery to use explicit ordering

@github-actions github-actions bot added the Documentation: build building the docs label Mar 19, 2026
doc/conf.py Outdated

sphinx_gallery_conf = {
'backreferences_dir': Path('api', '_as_gen'),
'minigallery_sort_order': ExplicitOrder([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wrong then, you're gonna want something more general (probably) - dig into the sphinx gallery side and see if there's a way to turn off sorting/pass a 'don't sort' key to sorted

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or write something like a yield function/counter such that every entry is mapped to its index (itertools should have something that does the trick). Basically a key function such that the input to sorted doesn't actually get sorted.

@MohitPal2005
Copy link
Author

@story645 Thanks for the feedback!

I’ve updated the implementation to preserve the intended ordering, and all checks are now passing. The docs build also looks correct on my end.

Please let me know if any further changes are needed.

@melissawm melissawm moved this from Waiting for author to Needs review in First Time Contributors Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation: build building the docs Documentation: tutorials files in galleries/tutorials first-contribution status: needs comment/discussion needs consensus on next step

Projects

Status: Needs review

Development

Successfully merging this pull request may close these issues.

Add thumbnails for tutorials/gallery where missing

3 participants