|
1 | 1 | """
|
2 | 2 | A directive for including a matplotlib plot in a Sphinx document.
|
3 | 3 |
|
4 |
| -By default, in HTML output, `plot` will include a .png file with a |
5 |
| -link to a high-res .png and .pdf. In LaTeX output, it will include a |
6 |
| -.pdf. |
| 4 | +By default, in HTML output, `plot` will include a .png file with a link to a |
| 5 | +high-res .png and .pdf. In LaTeX output, it will include a .pdf. |
7 | 6 |
|
8 | 7 | The source code for the plot may be included in one of three ways:
|
9 | 8 |
|
10 |
| - 1. **A path to a source file** as the argument to the directive:: |
| 9 | +1. **A path to a source file** as the argument to the directive:: |
11 | 10 |
|
12 |
| - .. plot:: path/to/plot.py |
| 11 | + .. plot:: path/to/plot.py |
13 | 12 |
|
14 |
| - When a path to a source file is given, the content of the |
15 |
| - directive may optionally contain a caption for the plot:: |
| 13 | + When a path to a source file is given, the content of the |
| 14 | + directive may optionally contain a caption for the plot:: |
16 | 15 |
|
17 |
| - .. plot:: path/to/plot.py |
| 16 | + .. plot:: path/to/plot.py |
18 | 17 |
|
19 |
| - This is the caption for the plot |
| 18 | + This is the caption for the plot |
20 | 19 |
|
21 |
| - Additionally, one may specify the name of a function to call (with |
22 |
| - no arguments) immediately after importing the module:: |
| 20 | + Additionally, one may specify the name of a function to call (with |
| 21 | + no arguments) immediately after importing the module:: |
23 | 22 |
|
24 |
| - .. plot:: path/to/plot.py plot_function1 |
| 23 | + .. plot:: path/to/plot.py plot_function1 |
25 | 24 |
|
26 |
| - 2. Included as **inline content** to the directive:: |
| 25 | +2. Included as **inline content** to the directive:: |
27 | 26 |
|
28 |
| - .. plot:: |
| 27 | + .. plot:: |
29 | 28 |
|
30 |
| - import matplotlib.pyplot as plt |
31 |
| - import matplotlib.image as mpimg |
32 |
| - import numpy as np |
33 |
| - img = mpimg.imread('_static/stinkbug.png') |
34 |
| - imgplot = plt.imshow(img) |
| 29 | + import matplotlib.pyplot as plt |
| 30 | + import matplotlib.image as mpimg |
| 31 | + import numpy as np |
| 32 | + img = mpimg.imread('_static/stinkbug.png') |
| 33 | + imgplot = plt.imshow(img) |
35 | 34 |
|
36 |
| - 3. Using **doctest** syntax:: |
| 35 | +3. Using **doctest** syntax:: |
37 | 36 |
|
38 |
| - .. plot:: |
39 |
| - A plotting example: |
40 |
| - >>> import matplotlib.pyplot as plt |
41 |
| - >>> plt.plot([1,2,3], [4,5,6]) |
| 37 | + .. plot:: |
| 38 | + A plotting example: |
| 39 | + >>> import matplotlib.pyplot as plt |
| 40 | + >>> plt.plot([1,2,3], [4,5,6]) |
42 | 41 |
|
43 | 42 | Options
|
44 | 43 | -------
|
|
53 | 52 | using the `plot_include_source` variable in conf.py
|
54 | 53 |
|
55 | 54 | encoding : str
|
56 |
| - If this source file is in a non-UTF8 or non-ASCII encoding, |
57 |
| - the encoding must be specified using the `:encoding:` option. |
58 |
| - The encoding will not be inferred using the ``-*- coding -*-`` |
59 |
| - metacomment. |
| 55 | + If this source file is in a non-UTF8 or non-ASCII encoding, the |
| 56 | + encoding must be specified using the `:encoding:` option. The encoding |
| 57 | + will not be inferred using the ``-*- coding -*-`` metacomment. |
60 | 58 |
|
61 | 59 | context : bool or str
|
62 |
| - If provided, the code will be run in the context of all |
63 |
| - previous plot directives for which the `:context:` option was |
64 |
| - specified. This only applies to inline code plot directives, |
65 |
| - not those run from files. If the ``:context: reset`` option is |
66 |
| - specified, the context is reset for this and future plots, and |
67 |
| - previous figures are closed prior to running the code. |
68 |
| - ``:context:close-figs`` keeps the context but closes previous figures |
69 |
| - before running the code. |
| 60 | + If provided, the code will be run in the context of all previous plot |
| 61 | + directives for which the `:context:` option was specified. This only |
| 62 | + applies to inline code plot directives, not those run from files. If |
| 63 | + the ``:context: reset`` option is specified, the context is reset |
| 64 | + for this and future plots, and previous figures are closed prior to |
| 65 | + running the code. ``:context: close-figs`` keeps the context but closes |
| 66 | + previous figures before running the code. |
70 | 67 |
|
71 | 68 | nofigs : bool
|
72 |
| - If specified, the code block will be run, but no figures will |
73 |
| - be inserted. This is usually useful with the ``:context:`` |
74 |
| - option. |
| 69 | + If specified, the code block will be run, but no figures will be |
| 70 | + inserted. This is usually useful with the ``:context:`` option. |
75 | 71 |
|
76 |
| -Additionally, this directive supports all of the options of the |
77 |
| -`image` directive, except for `target` (since plot will add its own |
78 |
| -target). These include `alt`, `height`, `width`, `scale`, `align` and |
79 |
| -`class`. |
| 72 | +Additionally, this directive supports all of the options of the `image` |
| 73 | +directive, except for `target` (since plot will add its own target). These |
| 74 | +include `alt`, `height`, `width`, `scale`, `align` and `class`. |
80 | 75 |
|
81 | 76 | Configuration options
|
82 | 77 | ---------------------
|
|
109 | 104 | that determine the file format and the DPI. For entries whose
|
110 | 105 | DPI was omitted, sensible defaults are chosen. When passing from
|
111 | 106 | the command line through sphinx_build the list should be passed as
|
112 |
| - suffix:dpi,suffix:dpi, .... |
| 107 | + suffix:dpi,suffix:dpi, ... |
113 | 108 |
|
114 | 109 | plot_html_show_formats
|
115 | 110 | Whether to show links to the files in HTML.
|
@@ -213,9 +208,8 @@ def _option_align(arg):
|
213 | 208 |
|
214 | 209 | def mark_plot_labels(app, document):
|
215 | 210 | """
|
216 |
| - To make plots referenceable, we need to move the reference from |
217 |
| - the "htmlonly" (or "latexonly") node to the actual figure node |
218 |
| - itself. |
| 211 | + To make plots referenceable, we need to move the reference from the |
| 212 | + "htmlonly" (or "latexonly") node to the actual figure node itself. |
219 | 213 | """
|
220 | 214 | for name, explicit in document.nametypes.items():
|
221 | 215 | if not explicit:
|
|
0 commit comments