Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f13c3df

Browse files
committed
Improve plot_directive's docstring and use it from the main docs.
1 parent 8521225 commit f13c3df

2 files changed

Lines changed: 26 additions & 37 deletions

File tree

doc/devel/documenting_mpl.rst

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -213,19 +213,6 @@ Figures can be automatically generated from scripts and included in
213213
the docs. It is not necessary to explicitly save the figure in the
214214
script, this will be done automatically at build time to ensure that
215215
the code that is included runs and produces the advertised figure.
216-
Several figures will be saved with the same basename as the filename
217-
when the documentation is generated (low and high res PNGs, a PDF).
218-
Matplotlib includes a Sphinx extension
219-
(:file:`sphinxext/plot_directive.py`) for generating the images from
220-
the python script and including either a png copy for html or a pdf
221-
for latex::
222-
223-
.. plot:: pyplots/pyplot_simple.py
224-
:include-source:
225-
226-
If the script produces multiple figures (through multiple calls to
227-
:func:`pyplot.figure`), each will be given a numbered file name and
228-
included.
229216

230217
The path should be relative to the ``doc`` directory. Any plots
231218
specific to the documentation should be added to the ``doc/pyplots``
@@ -238,8 +225,12 @@ directory. e.g.::
238225
The ``:scale:`` directive rescales the image to some percentage of the
239226
original size, though we don't recommend using this in most cases
240227
since it is probably better to choose the correct figure size and dpi
241-
in mpl and let it handle the scaling. ``:include-source:`` will
242-
present the contents of the file, marked up as source code.
228+
in mpl and let it handle the scaling.
229+
230+
Plot directive documentation
231+
''''''''''''''''''''''''''''
232+
233+
.. automodule:: matplotlib.sphinxext.plot_directive
243234

244235
Static figures
245236
--------------

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""
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.
43
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.
77
88
The source code for the plot may be included in one of three ways:
99
@@ -23,35 +23,33 @@
2323
2424
.. plot:: path/to/plot.py plot_function1
2525
26-
2. Included as inline content to the directive::
26+
2. Included as **inline content** to the directive::
2727
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)
2934
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::
3536
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])
4441
4542
Options
4643
-------
4744
48-
The ``plot`` directive supports the options:
45+
The ``plot`` directive supports the following options:
4946
5047
format : {'python', 'doctest'}
5148
Specify the format of the input
5249
5350
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
5553
5654
encoding : str
5755
If this source file is in a non-UTF8 or non-ASCII encoding,
@@ -61,7 +59,7 @@
6159
6260
context : bool
6361
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
6563
specified. This only applies to inline code plot directives,
6664
not those run from files.
6765

0 commit comments

Comments
 (0)