|
1 | 1 | """ |
2 | | -A special directive for including a matplotlib plot in a Sphinx |
3 | | -document. |
| 2 | +A directive for including a matplotlib plot in a Sphinx document. |
4 | 3 |
|
5 | | -In HTML output, `plot` will include a .png file with a link to a |
6 | | -high-res .png and .pdf. In LaTeX output, it will include a .pdf. |
| 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. |
7 | 7 |
|
8 | 8 | The source code for the plot may be included in one of three ways: |
9 | 9 |
|
|
23 | 23 |
|
24 | 24 | .. plot:: path/to/plot.py plot_function1 |
25 | 25 |
|
26 | | - 2. Included as inline content to the directive:: |
| 26 | + 2. Included as **inline content** to the directive:: |
27 | 27 |
|
28 | | - .. plot:: |
| 28 | + .. plot:: |
| 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) |
29 | 34 |
|
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) |
| 35 | + 3. Using **doctest** syntax:: |
35 | 36 |
|
36 | | - 3. Using doctest syntax:: |
37 | | -
|
38 | | - .. plot:: |
39 | | -
|
40 | | - A plotting example: |
41 | | -
|
42 | | - >>> import matplotlib.pyplot as plt |
43 | | - >>> plt.plot([1,2,3], [4,5,6]) |
| 37 | + .. plot:: foo |
| 38 | + A plotting example: |
| 39 | + >>> import matplotlib.pyplot as plt |
| 40 | + >>> plt.plot([1,2,3], [4,5,6]) |
44 | 41 |
|
45 | 42 | Options |
46 | 43 | ------- |
47 | 44 |
|
48 | | -The ``plot`` directive supports the options: |
| 45 | +The ``plot`` directive supports the following options: |
49 | 46 |
|
50 | 47 | format : {'python', 'doctest'} |
51 | 48 | Specify the format of the input |
52 | 49 |
|
53 | 50 | include-source : bool |
54 | | - Whether to display the source code. Default can be changed in conf.py |
| 51 | + Whether to display the source code. The default can be changed |
| 52 | + using the `plot_include_source` variable in conf.py |
55 | 53 |
|
56 | 54 | encoding : str |
57 | 55 | If this source file is in a non-UTF8 or non-ASCII encoding, |
|
61 | 59 |
|
62 | 60 | context : bool |
63 | 61 | If provided, the code will be run in the context of all |
64 | | - previous plot directives for which the context option was |
| 62 | + previous plot directives for which the `:context:` option was |
65 | 63 | specified. This only applies to inline code plot directives, |
66 | 64 | not those run from files. |
67 | 65 |
|
|
0 commit comments