DOC: use minigallery for tutorial thumbnails#31275
DOC: use minigallery for tutorial thumbnails#31275MohitPal2005 wants to merge 15 commits intomatplotlib:mainfrom
Conversation
|
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. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
|
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. |
|
Thank you for the clarification! I understand that tutorials use a different mechanism and that the correct I will look into the tutorials landing page and explore how the Please let me know if there are specific files or examples I should start with. |
|
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. |
|
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. |
|
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. |
What is your plan here? Your comments concern me a bit b/c they're mirroring mine but not really engaging w/ the contents. |
|
Thanks for pointing that out — that’s helpful. Here’s what I’m thinking for the page:
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. |
|
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. |
|
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:
|
|
|
||
| .. image:: /tutorials/images/thumb/sphx_glr_artists_thumb.png | ||
| :alt: Artist tutorial | ||
| .. minigallery:: |
There was a problem hiding this comment.
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
|
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. |
| ../galleries/tutorials/pyplot.py | ||
| ../galleries/tutorials/coding_shortcuts.py | ||
| ../galleries/tutorials/images.py |
There was a problem hiding this comment.
if you look at the output from this PR, you'll see that this doesn't affect the output:
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
doc/conf.py
Outdated
|
|
||
| sphinx_gallery_conf = { | ||
| 'backreferences_dir': Path('api', '_as_gen'), | ||
| 'minigallery_sort_order': ExplicitOrder([ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
|
@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. |

PR summary
This PR adds the
sphinx_gallery_thumbnail_numberdirective togalleries/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.