Skip to content

Commit 61a7860

Browse files
authored
Merge pull request #24201 from meeseeksmachine/auto-backport-of-pr-24194-on-v3.6.x
Backport PR #24194 on branch v3.6.x (DOC: Improve plot_directive documentation)
2 parents 075418d + 5c09db2 commit 61a7860

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

lib/matplotlib/sphinxext/plot_directive.py

+20-18
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
A directive for including a Matplotlib plot in a Sphinx document
33
================================================================
44
5-
By default, 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.
5+
This is a Sphinx extension providing a reStructuredText directive
6+
``.. plot::`` for including a plot in a Sphinx document.
77
8-
The source code for the plot may be included in one of three ways:
8+
In HTML output, ``.. plot::`` will include a .png file with a link
9+
to a high-res .png and .pdf. In LaTeX output, it will include a .pdf.
10+
11+
The plot content may be defined in one of three ways:
912
1013
1. **A path to a source file** as the argument to the directive::
1114
@@ -28,10 +31,8 @@
2831
.. plot::
2932
3033
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)
34+
plt.plot([1, 2, 3], [4, 5, 6])
35+
plt.title("A plotting exammple")
3536
3637
3. Using **doctest** syntax::
3738
@@ -44,22 +45,22 @@
4445
Options
4546
-------
4647
47-
The ``plot`` directive supports the following options:
48+
The ``.. plot::`` directive supports the following options:
4849
49-
format : {'python', 'doctest'}
50+
``:format:`` : {'python', 'doctest'}
5051
The format of the input. If unset, the format is auto-detected.
5152
52-
include-source : bool
53+
``:include-source:`` : bool
5354
Whether to display the source code. The default can be changed using
54-
the `plot_include_source` variable in :file:`conf.py` (which itself
55+
the ``plot_include_source`` variable in :file:`conf.py` (which itself
5556
defaults to False).
5657
57-
encoding : str
58+
``:encoding:`` : str
5859
If this source file is in a non-UTF8 or non-ASCII encoding, the
5960
encoding must be specified using the ``:encoding:`` option. The
6061
encoding will not be inferred using the ``-*- coding -*-`` metacomment.
6162
62-
context : bool or str
63+
``:context:`` : bool or str
6364
If provided, the code will be run in the context of all previous plot
6465
directives for which the ``:context:`` option was specified. This only
6566
applies to inline code plot directives, not those run from files. If
@@ -68,18 +69,19 @@
6869
running the code. ``:context: close-figs`` keeps the context but closes
6970
previous figures before running the code.
7071
71-
nofigs : bool
72+
``:nofigs:`` : bool
7273
If specified, the code block will be run, but no figures will be
7374
inserted. This is usually useful with the ``:context:`` option.
7475
75-
caption : str
76+
``:caption:`` : str
7677
If specified, the option's argument will be used as a caption for the
7778
figure. This overwrites the caption given in the content, when the plot
7879
is generated from a file.
7980
80-
Additionally, this directive supports all of the options of the `image`
81-
directive, except for *target* (since plot will add its own target). These
82-
include *alt*, *height*, *width*, *scale*, *align* and *class*.
81+
Additionally, this directive supports all the options of the `image directive
82+
<https://docutils.sourceforge.io/docs/ref/rst/directives.html#image>`_,
83+
except for ``:target:`` (since plot will add its own target). These include
84+
``:alt:``, ``:height:``, ``:width:``, ``:scale:``, ``:align:`` and ``:class:``.
8385
8486
Configuration options
8587
---------------------

0 commit comments

Comments
 (0)