Skip to content

DOC: Fix text tutorial thumbnails using sphinx_gallery_thumbnail_path#31224

Open
subhash-0000 wants to merge 6 commits intomatplotlib:mainfrom
subhash-0000:fix-text-tutorial-thumbnails
Open

DOC: Fix text tutorial thumbnails using sphinx_gallery_thumbnail_path#31224
subhash-0000 wants to merge 6 commits intomatplotlib:mainfrom
subhash-0000:fix-text-tutorial-thumbnails

Conversation

@subhash-0000
Copy link
Copy Markdown

This PR fixes the missing thumbnails for the PGF, usetex, and annotations tutorials in the "User Guide / Explain" section.

Why is this change necessary? These tutorials are currently showing the default Matplotlib logo placeholder instead of actual thumbnails. This happens because these examples rely on external dependencies (like LaTeX or specific backends) that may not be available during the automated documentation build process.

What problem does it solve? Setting sphinx_gallery_thumbnail_number is ineffective when no figures are generated during the build. This change implements the correct solution by using sphinx_gallery_thumbnail_path to point to pre-existing static images.

What is the reasoning for this implementation?

Researched the codebase and found that high-quality static thumbnails for these tutorials (e.g., pgf_preamble.png, usetex_tutorial.png) already exist in doc/_static/.
Found that the tutorial files originally had commented-out lines for these paths.
Uncommenting and correctly implementing these paths ensures the gallery shows valid thumbnails regardless of whether the backend is active during the build.
Closes #17479 (Addresses the Text tutorial portion of the tracking issue).

AI Disclosure
I used the Antigravity AI assistant to help identify the technical distinction between thumbnail_number and thumbnail_path and to help locate the existing static image assets within the Matplotlib directory structure.

PR checklist
"closes #17479" is in the body of the PR description
[N/A] new and changed code is tested
[N/A] Plotting related features are demonstrated in an example
[N/A] New Features and API Changes are noted with a directive and release note

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 2, 2026

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.

@github-actions github-actions bot added Documentation: user guide files in galleries/users_explain or doc/users first-contribution labels Mar 2, 2026
@story645
Copy link
Copy Markdown
Member

story645 commented Mar 2, 2026

Thanks for the PR, but users guide explain doesn't have thumbnails b/c there's no gallery there: https://matplotlib.org/devdocs/users/index.html

Unless you meant https://matplotlib.org/devdocs/users/explain/text/index.html but annotation already has a thumbnail.

@story645 story645 closed this Mar 2, 2026
@matplotlib matplotlib locked and limited conversation to collaborators Mar 2, 2026
@matplotlib matplotlib unlocked this conversation Mar 2, 2026
@story645 story645 reopened this Mar 2, 2026
@story645
Copy link
Copy Markdown
Member

story645 commented Mar 4, 2026

@subhash-0000
Copy link
Copy Markdown
Author

Hi @story645, thanks for the guidance. I've updated the PR to address both of your points:

User Guide Index (users/index.html): You were right that this page felt bare. I've added thumbnails (Anatomy, Figure widgets, etc.) to the Quick start, Figure, and Text section cards using the :img-top: directive. This transforms the landing page into a visual 'gallery' entryway as requested.
Explicit Thumbnails: I've explicitly enabled sphinx_gallery_thumbnail_path in the gallery scripts and included the actual image assets in this commit. This ensures we use high-quality, pre-rendered thumbnails instead of relying on the auto-generated plot previews.
CI & Linting: I've also resolved the module-level import errors (E402) that appeared in the CI, and all checks are now green.
The User Guide should now have a consistent, visual-first feel from the main index down to the individual tutorials.

@story645
Copy link
Copy Markdown
Member

story645 commented Mar 4, 2026

User Guide Index (users/index.html): You were right that this page felt bare. I've added thumbnails (Anatomy, Figure widgets, etc.) to the Quick start, Figure, and Text section cards using the :img-top: directive. This transforms the landing page into a visual 'gallery' entryway as requested.

Please split this off into a separate PR as it's a separate discussion. Also why did you choose those?

This ensures we use high-quality, pre-rendered thumbnails instead of relying on the auto-generated plot previews.

We want to use the auto-generated plots b/c those are guaranteed to stay in sync.

Which neither of these changes address that this PR does not fix the problem of missing thumbnails.

@subhash-0000 subhash-0000 force-pushed the fix-text-tutorial-thumbnails branch from 29afed6 to 9e92390 Compare March 4, 2026 07:51
@story645
Copy link
Copy Markdown
Member

story645 commented Mar 4, 2026

Much improved, but now math text looks wonky. Also can you do something for fonts? Maybe the font fallback image that's already in the tutorial?
image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

you shouldn't need this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nor this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would use the image in the tutorial, which is likely saved somewhere

Image

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I've replaced it with a figure that matches the first image embedded in the tutorial — the cosine wave with the "TeX is Number" formula title, rendered via mathtext (no LaTeX required for the static image). If you'd prefer a different image from the tutorial, happy to swap it out

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the goal is no saved image/use the one that's already embedded in the file

Copy link
Copy Markdown
Member

@story645 story645 left a comment

Choose a reason for hiding this comment

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

I think for the linting errors, might be easier to just turn off liniting.

Here is the standard example,
:doc:`/gallery/text_labels_and_annotations/tex_demo`:

.. figure:: /gallery/text_labels_and_annotations/images/sphx_glr_tex_demo_001.png
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

instead of saving a static image, can you point the thumbnail to this file too?

Comment on lines +168 to +169
sphinx_gallery_thumbnail_path = (
'gallery/text_labels_and_annotations/images/sphx_glr_tex_demo_001.png')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this isn't working so look at if we use the gallery paths for other thumbnails to see how this should be specified

@subhash-0000 subhash-0000 force-pushed the fix-text-tutorial-thumbnails branch from 947713f to 6002dec Compare March 22, 2026 07:07
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the goal is no saved image/use the one that's already embedded in the file

Comment on lines +168 to +169
# sphinx_gallery_thumbnail_path = (
# 'gallery/text_labels_and_annotations/images/sphx_glr_tex_demo_001.png')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# sphinx_gallery_thumbnail_path = (
# 'gallery/text_labels_and_annotations/images/sphx_glr_tex_demo_001.png')
# sphinx_gallery_thumbnail_path = (
# '/gallery/text_labels_and_annotations/images/sphx_glr_tex_demo_001.png')

this still isn't working, try more urls? Note, the path to the image should be relative to the conf.py

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

Labels

Documentation: user guide files in galleries/users_explain or doc/users first-contribution

Projects

Status: Waiting for author

Development

Successfully merging this pull request may close these issues.

Add thumbnails for tutorials/gallery where missing

3 participants