Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c78c810

Browse filesBrowse files
committed
Copy edit changelog entry
1 parent 00860f8 commit c78c810
Copy full SHA for c78c810

File tree

3 files changed

+34
-63
lines changed
Filter options

3 files changed

+34
-63
lines changed

‎doc/users/next_whats_new/2018_12_03_sphinx_plot_preserve.rst

Copy file name to clipboardExpand all lines: doc/users/next_whats_new/2018_12_03_sphinx_plot_preserve.rst
-61Lines changed: 0 additions & 61 deletions
This file was deleted.
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Caching sphinx directive figure outputs
2+
---------------------------------------
3+
4+
The new ``:outname:`` property for the Sphinx plot directive can
5+
be used to cache generated images. It is used like:
6+
7+
.. code-block:: rst
8+
9+
.. plot::
10+
:outname: stinkbug_plot
11+
12+
import matplotlib.pyplot as plt
13+
import matplotlib.image as mpimg
14+
import numpy as np
15+
img = mpimg.imread('_static/stinkbug.png')
16+
imgplot = plt.imshow(img)
17+
18+
Without ``:outname:``, the figure generated above would normally be called,
19+
e.g. :file:`docfile3-4-01.png` or something equally mysterious. With
20+
``:outname:`` the figure generated will instead be named
21+
:file:`stinkbug_plot-01.png` or even :file:`stinkbug_plot.png`. This makes it
22+
easy to understand which output image is which and, more importantly, uniquely
23+
keys output images to the code snippets that generated them.
24+
25+
Configuring the cache directory
26+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27+
The directory that images are cached to can be configured using the
28+
``plot_cache_dir`` configuration value in the Sphinx configuration file.
29+
30+
If an image is already in ``plot_cache_dir`` when documentation is being
31+
generated, this image is copied to the build directory thereby pre-empting
32+
generation and reducing computation time in low-resource environments.

‎lib/matplotlib/sphinxext/plot_directive.py

Copy file name to clipboardExpand all lines: lib/matplotlib/sphinxext/plot_directive.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@
7979
is generated from a file.
8080
``:outname:`` : str
8181
If specified, the names of the generated plots will start with the
82-
value of `:outname:`. This is handy for preserving output results if
83-
code is reordered between runs. The value of `:outname:` must be
82+
value of ``:outname:``. This is handy for preserving output results if
83+
code is reordered between runs. The value of ``:outname:`` must be
8484
unique across the generated documentation.
8585
8686
Additionally, this directive supports all the options of the `image directive

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.