@@ -43,16 +43,17 @@ guide, developers guide, api reference, and FAQs. The documentation suite is
43
43
built as a single document in order to make the most effective use of cross
44
44
referencing.
45
45
46
- .. note ::
47
-
48
- An exception to this are the directories :file: `examples ` and
49
- :file: `tutorials `, which exist in the root directory. These contain Python
50
- files that are built by `Sphinx Gallery `_. When the docs are built,
51
- the directories :file: `docs/gallery ` and :file: `docs/tutorials `
52
- are automatically generated. Do not edit the rst files in :file: docs/gallery
53
- and :file: docs/tutorials, as they are rebuilt from the original sources in
54
- the root directory.
55
-
46
+ Sphinx _ also creates ``.rst `` files that are staged in :file: `doc/api ` from
47
+ the docstrings of the classes in the Matplotlib library. Except for
48
+ :file: `doc/api/api_changes/ `, these ``.rst `` are created when the
49
+ documentation is built.
50
+
51
+ Similarly, the contents of :file: `docs/gallery ` and :file: `docs/tutorials ` are
52
+ generated by the `Sphinx Gallery `_ from the sources in :file: `examples ` and
53
+ :file: `tutorials `. These sources consist of python scripts that have ReST
54
+ documentation built into their comments. Again, don't directly edit the
55
+ ``.rst `` files in :file: `docs/gallery ` and :file: `docs/tutorials ` as they are
56
+ regenerated when the documentation are built.
56
57
57
58
Additional files can be added to the various guides by including their base
58
59
file name (the .rst extension is not necessary) in the table of contents.
@@ -96,7 +97,8 @@ code that explain how the code works. All new or edited docstrings should
96
97
conform to the numpydoc guidelines. These split the docstring into a number
97
98
of sections - see
98
99
https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt for more
99
- details and a guide to how docstrings should be formatted.
100
+ details and a guide to how docstrings should be formatted. These docstrings
101
+ eventually populate the :file: `doc/api ` directory.
100
102
101
103
An example docstring looks like:
102
104
@@ -136,6 +138,8 @@ An example docstring looks like:
136
138
axhline: horizontal line across the axes
137
139
"""
138
140
141
+ See the `~.Axes.hlines ` for how this renders.
142
+
139
143
The Sphinx website also contains plenty of documentation _ concerning ReST
140
144
markup and working with Sphinx in general.
141
145
@@ -148,10 +152,16 @@ the name to refer to in back ticks, for example:
148
152
149
153
`~ matplotlib.collections.LineCollection`
150
154
151
- It is also possible to add links to code in Python, Numpy, Scipy, or Pandas.
152
- Sometimes it is tricky to get external Sphinx linking to work; to check that
153
- a something exists to link to the following shell command outputs a list of all
154
- objects that can be referenced (in this case for Numpy)::
155
+ We can also link to other packages via ``intersphinx ``:
156
+
157
+ .. code-block :: Python
158
+
159
+ `numpy.mean`
160
+
161
+ will return this link: `numpy.mean `. This works for Python, Numpy, Scipy,
162
+ and Pandas. Sometimes it is tricky to get external Sphinx linking to work; to
163
+ check that a something exists to link to the following shell command outputs
164
+ a list of all objects that can be referenced (in this case for Numpy)::
155
165
156
166
python -m sphinx.ext.intersphinx 'https://docs.scipy.org/doc/numpy/objects.inv'
157
167
@@ -181,12 +191,15 @@ nor the ````literal```` role:
181
191
182
192
Setters and getters
183
193
-------------------
184
- Matplotlib uses artist introspection of docstrings to support properties.
185
- All properties that you want to support through `~.pyplot.setp ` and
186
- `~.pyplot.getp ` should have a ``set_property `` and ``get_property `` method in
187
- the `~.matplotlib.artist.Artist ` class. The setter methods use the docstring
188
- with the ACCEPTS token to indicate the type of argument the method accepts.
189
- e.g., in `.Line2D `:
194
+
195
+ Artist properties are implemented using setter and getter methods (because
196
+ Matplotlib predates the introductions of the `property ` decorator in Python).
197
+ By convention, these setters and getters are named ``set_PROPERTYNAME `` and
198
+ ``get_PROPERTYNAME ``; the list of properties thusly defined on an artist and
199
+ their values can be listed by the `~.pyplot.setp ` and `~.pyplot.getp ` functions.
200
+
201
+ Property setter methods should indicate the values they accept using a (legacy)
202
+ special block in the docstring, starting with ``ACCEPTS ``, as follows:
190
203
191
204
.. code-block :: python
192
205
@@ -198,8 +211,21 @@ e.g., in `.Line2D`:
198
211
ACCEPTS: [ '-' | '--' | '-.' | ':' | 'steps' | 'None' | ' ' | '' ]
199
212
"""
200
213
214
+ The ACCEPTS block is used to render a table of all properties and their
215
+ acceptable values in the docs; it can also be displayed using, e.g.,
216
+ ``plt.setp(Line2D) `` (all properties) or ``plt.setp(Line2D, 'linestyle') ``
217
+ (just one property).
218
+
201
219
Keyword arguments
202
220
-----------------
221
+
222
+ .. note ::
223
+
224
+ The information in this section is being actively discussed by the
225
+ development team, so use the docstring interpolation only if necessary.
226
+ This section has been left in place for now because this interpolation
227
+ is part of the existing documentation.
228
+
203
229
Since Matplotlib uses a lot of pass-through ``kwargs ``, e.g., in every function
204
230
that creates a line (`~.pyplot.plot `, `~.pyplot.semilogx `, `~.pyplot.semilogy `,
205
231
etc...), it can be difficult for the new user to know which ``kwargs `` are
0 commit comments