X Tutup
Skip to content

DOC: Add thumbnail for multipage_pdf gallery example#31308

Merged
story645 merged 1 commit intomatplotlib:mainfrom
AMAN194701:add-multipage-pdf-thumbnail
Mar 17, 2026
Merged

DOC: Add thumbnail for multipage_pdf gallery example#31308
story645 merged 1 commit intomatplotlib:mainfrom
AMAN194701:add-multipage-pdf-thumbnail

Conversation

@AMAN194701
Copy link
Copy Markdown
Contributor

Problem

The multipage_pdf example does not generate a gallery thumbnail.

Cause

The example uses pdf.savefig() instead of plt.savefig(), so Sphinx Gallery cannot auto-generate a thumbnail.

Fix

Added a static thumbnail using sphinx_gallery_thumbnail_path.

Closes #17479

@github-actions github-actions bot added the Documentation: examples files in galleries/examples label Mar 15, 2026
@AMAN194701
Copy link
Copy Markdown
Contributor Author

CI checks failed — I'm investigating the error. Please let me know if you can see the issue from your end or how can i resolve it. Thank you!

@rcomer
Copy link
Copy Markdown
Member

rcomer commented Mar 15, 2026

The doc build failure appears to be a problem with linking to pandas' documentation so not caused by this PR. However, the build was successful enough that we can look at the relevant thumbnails here:
https://output.circle-artifacts.com/output/job/ce929f36-3f22-414e-8793-6809dc5e88da/artifacts/0/doc/build/html/gallery/misc/index.html

Multpage PDF is still showing the default thumbnail, not the one you are trying to add. I'm also not sure how useful the proposed image is. If a user is actively looking for guidance how to make a multipage pdf, will a line plot indicate that this is the place to click?

@Ker102
Copy link
Copy Markdown

Ker102 commented Mar 15, 2026

Hey @AMAN194701, I took a look at why the thumbnail isn't showing up in the CI build.

The issue is that sphinx_gallery_thumbnail_path is placed on line 1, before the module docstring. Sphinx Gallery only picks up this directive when it appears as a comment below the docstring (see the Sphinx Gallery docs for the expected placement).

Here's the fix — just move the directive after the imports:

-# sphinx_gallery_thumbnail_path = '_static/multipage_pdf_thumbnail.png'
 """
 =============
 Multipage PDF
 =============
 ...
 """

 import datetime

 import matplotlib.pyplot as plt
 import numpy as np

 from matplotlib.backends.backend_pdf import PdfPages
+
+# sphinx_gallery_thumbnail_path = '_static/multipage_pdf_thumbnail.png'

Regarding @rcomer's point about the thumbnail image — that's a fair consideration. Since this example produces three different plots saved into a PDF, the "Page One" line plot does represent what the example actually generates. But it might also be worth following the discussion on #17479 about whether a custom default thumbnail via default_thumb_file would be a better global solution for all the missing-thumbnail cases.

@AMAN194701
Copy link
Copy Markdown
Contributor Author

Thank you @rcomer and @Ker102 for the feedback! I'll move the directive to after the docstring right away and push the fix

@AMAN194701
Copy link
Copy Markdown
Contributor Author

AMAN194701 commented Mar 15, 2026

The thumbnail is now showing correctly in the built docs as you can see here: https://output.circle-artifacts.com/output/job/cf9ec523-efed-4d19-8358-c87be23e2f6c/artifacts/0/doc/build/html/gallery/misc/index.html. The fix was to move the sphinx_gallery_thumbnail_path directive to after the imports as suggested by @Ker102. The CI failure appears to be the pre-existing pandas documentation 404 issue as mentioned by @rcomer, not related to my changes.

@story645
Copy link
Copy Markdown
Member

Thanks for working on this, but I agree w/ @Ker102 and @rcomer that the line plot isn't an informative thumbnail here. I'd either go w/ something custom to this image (an image of a multi page PDF w/ an open license) or a default "no image" to indicate the example isn't broken.

@AMAN194701
Copy link
Copy Markdown
Contributor Author

Thank you @story645! Should I use the default 'no image' approach — would that mean setting up the global default_thumb_file in conf.py as suggested by @rcomer, or should I create a custom image of a multi-page PDF? Happy to go with whatever works best!

@story645
Copy link
Copy Markdown
Member

Happy to go with whatever works best!

I dunno, propose examples of both and see what folks like? I'm sorry that's more work, but this is one of those things I doubt anyone will have strong opinions on until they see things to have opinions on.

@AMAN194701
Copy link
Copy Markdown
Contributor Author

Thank you @story645! I'll try both and share here so everyone can give feedback.

@AMAN194701
Copy link
Copy Markdown
Contributor Author

AMAN194701 commented Mar 16, 2026

hey @rcomer @story645 the pr_clean check is failing because i added and then updated the same image in the PR. should i squash the commits to fix this?

@story645
Copy link
Copy Markdown
Member

hould i squash the commits to fix this?

Yes

@AMAN194701 AMAN194701 force-pushed the add-multipage-pdf-thumbnail branch from 4c48692 to 760b7f9 Compare March 16, 2026 21:23
@AMAN194701
Copy link
Copy Markdown
Contributor Author

Here are both options for feedback!

option 1 - custom multipage pdf design (already showing in PR build): [ https://output.circle-artifacts.com/output/job/6d1d0642-aa09-49cb-a776-5e1e4f04a444/artifacts/0/doc/build/html/gallery/misc/index.html ]

Screenshot 2026-03-17 at 12 52 06

option 2 - simple no preview placeholder:
Screenshot 2026-03-17 at 12 56 38

which one works better? @story645

@timhoffm
Copy link
Copy Markdown
Member

timhoffm commented Mar 17, 2026

I like option 1.

Could this be an svg so that it also looks good on high-res screens? To be checked whether sphinx-gallery supports this.

@AMAN194701
Copy link
Copy Markdown
Contributor Author

Thanks @timhoffm for the suggestion!!
I’ll check whether Sphinx-Gallery supports SVG thumbnails properly, and try converting the current design to SVG to see how it renders in the gallery and I’ll update here once I test it.

@AMAN194701 AMAN194701 force-pushed the add-multipage-pdf-thumbnail branch from 760b7f9 to f09cdb3 Compare March 17, 2026 12:14
@AMAN194701
Copy link
Copy Markdown
Contributor Author

Thanks @timhoffm and @story645 for the suggestion !

I checked whether Sphinx-Gallery supports SVG thumbnails — it does. Converted the thumbnail from PNG to SVG so it renders sharply on high-res screens.
Here's how it looks:
Screenshot 2026-03-17 at 18 08 13

And here's the gallery page from the CI build: https://output.circle-artifacts.com/output/job/445260f0-2a71-4926-ab4a-75e23f438a5f/artifacts/0/doc/build/html/gallery/misc/index.html

All CI checks are passing ✅

@rcomer
Copy link
Copy Markdown
Member

rcomer commented Mar 17, 2026

I like the new svg image but it seems quite small in the gallery compared with other images. Would reducing white space around the edges help that?

@AMAN194701
Copy link
Copy Markdown
Contributor Author

AMAN194701 commented Mar 17, 2026

Thanks @rcomer !
Yes, that makes sense — I'll reduce the white space around the edges so the image fills the thumbnail better. I will push a fix shortly

@AMAN194701 AMAN194701 force-pushed the add-multipage-pdf-thumbnail branch from f09cdb3 to 5bb2ce0 Compare March 17, 2026 14:22
@AMAN194701 AMAN194701 force-pushed the add-multipage-pdf-thumbnail branch from 5bb2ce0 to 453b8ab Compare March 17, 2026 14:54
@AMAN194701
Copy link
Copy Markdown
Contributor Author

Updated the thumbnail — reduced white space so it fills the card better. Here's how it looks in the CI-built gallery:

Screenshot 2026-03-17 at 20 47 11

Built docs: https://output.circle-artifacts.com/output/job/887e62eb-9252-4c7a-b91b-2b6e596394f6/artifacts/0/doc/build/html/gallery/misc/index.html
@rcomer @timhoffm @story645

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.

Thanks for seeing this through! Before I merge, can you confirm that you either made the image yourself or provide the source/license for the image?

@story645 story645 added the DO NOT MERGE Last-resort; prefer specific mechanisms if possible: draft PR, request changes, specific labels label Mar 17, 2026
@AMAN194701
Copy link
Copy Markdown
Contributor Author

AMAN194701 commented Mar 17, 2026

Thanks @story645! Yes, I made the SVG myself from scratch — it's original work.

@story645 story645 removed the DO NOT MERGE Last-resort; prefer specific mechanisms if possible: draft PR, request changes, specific labels label Mar 17, 2026
@story645 story645 added this to the v3.11.0 milestone Mar 17, 2026
@story645 story645 merged commit 315010b into matplotlib:main Mar 17, 2026
23 of 24 checks passed
@AMAN194701 AMAN194701 deleted the add-multipage-pdf-thumbnail branch March 18, 2026 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation: examples files in galleries/examples

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add thumbnails for tutorials/gallery where missing

5 participants

X Tutup