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

Skip to content

Commit d4f97ef

Browse files
committed
DOC: Minor enhancements to documenting_mpl
1 parent 2f897dc commit d4f97ef

File tree

1 file changed

+47
-21
lines changed

1 file changed

+47
-21
lines changed

doc/devel/documenting_mpl.rst

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,17 @@ guide, developers guide, api reference, and FAQs. The documentation suite is
4343
built as a single document in order to make the most effective use of cross
4444
referencing.
4545

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.
5657

5758
Additional files can be added to the various guides by including their base
5859
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
9697
conform to the numpydoc guidelines. These split the docstring into a number
9798
of sections - see
9899
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.
100102

101103
An example docstring looks like:
102104

@@ -136,6 +138,8 @@ An example docstring looks like:
136138
axhline: horizontal line across the axes
137139
"""
138140
141+
See the `~.Axes.hlines` for how this renders.
142+
139143
The Sphinx website also contains plenty of documentation_ concerning ReST
140144
markup and working with Sphinx in general.
141145

@@ -148,10 +152,16 @@ the name to refer to in back ticks, for example:
148152
149153
`~matplotlib.collections.LineCollection`
150154
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)::
155165

156166
python -m sphinx.ext.intersphinx 'https://docs.scipy.org/doc/numpy/objects.inv'
157167

@@ -181,12 +191,15 @@ nor the ````literal```` role:
181191
182192
Setters and getters
183193
-------------------
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:
190203

191204
.. code-block:: python
192205
@@ -198,8 +211,21 @@ e.g., in `.Line2D`:
198211
ACCEPTS: [ '-' | '--' | '-.' | ':' | 'steps' | 'None' | ' ' | '' ]
199212
"""
200213
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+
201219
Keyword arguments
202220
-----------------
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+
203229
Since Matplotlib uses a lot of pass-through ``kwargs``, e.g., in every function
204230
that creates a line (`~.pyplot.plot`, `~.pyplot.semilogx`, `~.pyplot.semilogy`,
205231
etc...), it can be difficult for the new user to know which ``kwargs`` are

0 commit comments

Comments
 (0)