Repository navigation
Plot directive preserve #10149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Plot directive preserve #10149
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b8c5559
Added `:outname:` option and `plot_preserve_dir` configuration value
r-barnes d4c41ff
Added What's New for plot directive changes
r-barnes 69356da
Futzing with PEP8 whitespace stuff.
r-barnes 8b477a4
Fix grammer
r-barnes fddd490
Fix bug with adding null string to outname_list
r-barnes 872faa1
Added a test of `:outname:`
r-barnes 0ee71f0
Examples of using rst need to be code blocks
r-barnes 082298e
Use logging instead of print
r-barnes 73858c1
Satisfy PEP8 checks
r-barnes 74e9fbc
FIX: issue with rebase due to re-naming of local variables
tacaswell cd78416
STY: fix line length and indentation issues
tacaswell 725f25d
STY: trim whitespace and add trailing comma
tacaswell 134aaf9
Fix doc style
timhoffm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added What's New for plot directive changes
- Loading branch information
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
doc/users/next_whats_new/2018_12_03_sphinx_plot_preserve.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| Plot Directive `outname` and `plot_preserve_dir` | ||
| ---------------------------------------------------- | ||
|
|
||
| The Sphinx plot directive can be used to automagically generate figures for | ||
| documentation like so: | ||
|
|
||
| .. plot:: | ||
|
|
||
| import matplotlib.pyplot as plt | ||
| import matplotlib.image as mpimg | ||
| import numpy as np | ||
| img = mpimg.imread('_static/stinkbug.png') | ||
| imgplot = plt.imshow(img) | ||
|
|
||
| But, if you reorder the figures in the documentation then all the figures may | ||
| need to be rebuilt. This takes time. The names given to the figures are also | ||
| fairly meaningless, making them more difficult to index by search engines or to | ||
| find on a filesystem. | ||
|
|
||
| Alternatively, if you are compiling on a limited-resource service like | ||
| ReadTheDocs, you may wish to build imagery locally to avoid hitting resource | ||
| limits on the server. Using the new changes allows extensive dynamically | ||
| generated imagery to be used on services like ReadTheDocs. | ||
|
|
||
| The `:outname:` property | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| These problems are address through two new features in the plot directive. The | ||
| first is the introduction of the `:outname:` property. It is used like so: | ||
|
|
||
| .. plot:: | ||
| :outname: stinkbug_plot | ||
|
|
||
| import matplotlib.pyplot as plt | ||
| import matplotlib.image as mpimg | ||
| import numpy as np | ||
| img = mpimg.imread('_static/stinkbug.png') | ||
| imgplot = plt.imshow(img) | ||
|
|
||
| Without `:outname:`, the figure generated above would normally be called, e.g. | ||
| `docfile3-4-01.png` or something equally mysterious. With `:outname:` the figure | ||
| generated will instead be named `stinkbug_plot-01.png` or even | ||
| `stinkbug_plot.png`. This makes it easy to understand which output image is | ||
| which and, more importantly, uniquely keys output images to code snippets. | ||
|
|
||
| The `plot_preserve_dir` configuration value | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Setting the `plot_preserve_dir` configuration value to the name of a directory | ||
| will cause all images with `:outname:` set to be copied to this directory upon | ||
| generation. | ||
|
|
||
| If an image is already in `plot_preserve_dir` when documentation is being | ||
| generated, this image is copied to the build directory thereby pre-empting | ||
| generation and reducing computation time in low-resource environments. | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose to rename
plot_preserve_dirtoplot_cache_dir.