Description
Bug summary
Using the Matplotlib plot directive in Sphinx documentation results in cluttering the output directory with all the produced image files in all generated formats even when they are not needed (plot_html_show_formats = False
). This is especially obvious with the singlehtml
builder, where all the necessary images must be inside the _images
subdirectory, but in fact, in addition to _images
, the whole directory tree with every image in every format is copied to the output directory, although nothing of it is referenced from the HTML file.
What is more interesting, if another builder is executed first, then its cached images are reused properly — only the necessary files are copied into _images
, without cluttering the output directory with unneeded files and subdirectories.
Code for reproduction
See a minimal working example at https://github.com/MikhailRyazanov/plot-clutter.
Actual outcome
From step 1 of the example above:
$ tree build/singlehtml
build/singlehtml
├── _images
│ ├── index-1.svg
│ ├── other-1.svg
│ └── script.svg
├── index-1.pdf
├── index-1.svg
├── index.html
├── objects.inv
├── _static
│ <skipped>
└── subdir
├── other-1.pdf
├── other-1.svg
├── script.pdf
└── script.svg
Expected outcome
From step 2 of the example above:
build/singlehtml
├── _images
│ ├── index-1.svg
│ ├── other-1.svg
│ └── script.svg
├── index.html
├── objects.inv
└── _static
<skipped>
Additional information
In practice, this undesired behavior directly affects the downloadable documentation at Read the docs — see issue #9068 there.
Operating system
No response
Matplotlib Version
3.5.2
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
Linux package manager