8000 Move setter/getter/kwarg section to near bottom · matplotlib/matplotlib@5aeb87d · GitHub
[go: up one dir, main page]

Skip to content

Commit 5aeb87d

Browse files
committed
Move setter/getter/kwarg section to near bottom
1 parent 45709fa commit 5aeb87d

File tree

1 file changed

+81
-81
lines changed

1 file changed

+81
-81
lines changed

doc/devel/documenting_mpl.rst

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -90,87 +90,6 @@ statement, such as::
9090

9191
.. include:: ../../TODO
9292

93-
docstrings
94-
----------
95-
96-
In addition to the "narrative" documentation described above,
97-
Matplotlib also defines its API reference documentation in docstrings.
98-
For the most part, these are standard Python docstrings, but
99-
Matplotlib also includes some features to better support documenting
100-
getters and setters.
101-
102-
Matplotlib uses artist introspection of docstrings to support properties.
103-
All properties that you want to support through `~.pyplot.setp` and
104-
`~.pyplot.getp` should have a ``set_property`` and ``get_property`` method in
105-
the `~.matplotlib.artist.Artist` class. The setter methods use the docstring
106-
with the ACCEPTS token to indicate the type of argument the method accepts.
107-
e.g., in `.Line2D`:
108-
109-
.. code-block:: python
110-
111-
# in lines.py
112-
def set_linestyle(self, linestyle):
113-
"""
114-
Set the linestyle of the line
115-
116-
ACCEPTS: [ '-' | '--' | '-.' | ':' | 'steps' | 'None' | ' ' | '' ]
117-
"""
118-
119-
Since Matplotlib uses a lot of pass-through ``kwargs``, e.g., in every function
120-
that creates a line (`~.pyplot.plot`, `~.pyplot.semilogx`, `~.pyplot.semilogy`,
121-
etc...), it can be difficult for the new user to know which ``kwargs`` are
122-
supported. Matplotlib uses a docstring interpolation scheme to support
123-
documentation of every function that takes a ``**kwargs``. The requirements
124-
are:
125-
126-
1. single point of configuration so changes to the properties don't
127-
require multiple docstring edits.
128-
129-
2. as automated as possible so that as properties change, the docs
130-
are updated automatically.
131-
132-
The function `matplotlib.artist.kwdoc` and the decorator
133-
`matplotlib.docstring.dedent_interpd` facilitate this. They combine Python
134-
string interpolation in the docstring with the Matplotlib artist introspection
135-
facility that underlies ``setp`` and ``getp``. The ``kwdoc`` function gives
136-
the list of properties as a docstring. In order to use this in another
137-
docstring, first update the ``matplotlib.docstring.interpd`` object, as seen in
138-
this example from `matplotlib.lines`:
139-
140-
.. code-block:: python
141-
142-
# in lines.py
143-
docstring.interpd.update(Line2D=artist.kwdoc(Line2D))
144-
145-
Then in any function accepting `~.Line2D` pass-through ``kwargs``, e.g.,
146-
`matplotlib.axes.Axes.plot`:
147-
148-
.. code-block:: python
149-
150-
# in axes.py
151-
@docstring.dedent_interpd
152-
def plot(self, *args, **kwargs):
153-
"""
154-
Some stuff omitted
155-
156-
The kwargs are Line2D properties:
157-
%(Line2D)s
158-
159-
kwargs scalex and scaley, if defined, are passed on
160-
to autoscale_view to determine whether the x and y axes are
161-
autoscaled; default True. See Axes.autoscale_view for more
162-
information
163-
"""
164-
pass
165-
166-
Note there is a problem for `~matplotlib.artist.Artist` ``__init__`` methods,
167-
e.g., `matplotlib.patches.Patch.__init__`, which supports ``Patch`` ``kwargs``,
168-
since the artist inspector cannot work until the class is fully defined and
169-
we can't modify the ``Patch.__init__.__doc__`` docstring outside the class
170-
definition. There are some some manual hacks in this case, violating the
171-
"single entry point" requirement above -- see the ``docstring.interpd.update``
172-
calls in `matplotlib.patches`.
173-
17493
.. _formatting-mpl-docs:
17594

17695
Formatting
@@ -460,6 +379,87 @@ For everything but top level chapters, please use ``Upper lower`` for
460379
section titles, e.g., ``Possible hangups`` rather than ``Possible
461380
Hangups``
462381

382+
Setters, getters, and keyword arguments
383+
=======================================
384+
385+
In addition to the "narrative" documentation described above,
386+
Matplotlib also defines its API reference documentation in docstrings.
387+
For the most part, these are standard Python docstrings, but
388+
Matplotlib also includes some features to better support documenting
389+
getters and setters.
390+
391+
Matplotlib uses artist introspection of docstrings to support properties.
392+
All properties that you want to support through `~.pyplot.setp` and
393+
`~.pyplot.getp` should have a ``set_property`` and ``get_property`` method in
394+
the `~.matplotlib.artist.Artist` class. The setter methods use the docstring
395+
with the ACCEPTS token to indicate the type of argument the method accepts.
396+
e.g., in `.Line2D`:
397+
398+
.. code-block:: python
399+
400+
# in lines.py
401+
def set_linestyle(self, linestyle):
402+
"""
403+
Set the linestyle of the line
404+
405+
ACCEPTS: [ '-' | '--' | '-.' | ':' | 'steps' | 'None' | ' ' | '' ]
406+
"""
407+
408+
Since Matplotlib uses a lot of pass-through ``kwargs``, e.g., in every function
409+
that creates a line (`~.pyplot.plot`, `~.pyplot.semilogx`, `~.pyplot.semilogy`,
410+
etc...), it can be difficult for the new user to know which ``kwargs`` are
411+
supported. Matplotlib uses a docstring interpolation scheme to support
412+
documentation of every function that takes a ``**kwargs``. The requirements
413+
are:
414+
415+
1. single point of configuration so changes to the properties don't
416+
require multiple docstring edits.
417+
418+
2. as automated as possible so that as properties change, the docs
419+
are updated automatically.
420+
421+
The function `matplotlib.artist.kwdoc` and the decorator
422+
`matplotlib.docstring.dedent_interpd` facilitate this. They combine Python
423+
string interpolation in the docstring with the Matplotlib artist introspection
424+
facility that underlies ``setp`` and ``getp``. The ``kwdoc`` function gives
425+
the list of properties as a docstring. In order to use this in another
426+
docstring, first update the ``matplotlib.docstring.interpd`` object, as seen in
427+
this example from `matplotlib.lines`:
428+
429+
.. code-block:: python
430+
431+
# in lines.py
432+
docstring.interpd.update(Line2D=artist.kwdoc(Line2D))
433+
434+
Then in any function accepting `~.Line2D` pass-through ``kwargs``, e.g.,
435+
`matplotlib.axes.Axes.plot`:
436+
437+
.. code-block:: python
438+
439+
# in axes.py
440+
@docstring.dedent_interpd
441+
def plot(self, *args, **kwargs):
442+
"""
443+
Some stuff omitted
444+
445+
The kwargs are Line2D properties:
446+
%(Line2D)s
447+
448+
kwargs scalex and scaley, if defined, are passed on
449+
to autoscale_view to determine whether the x and y axes are
450+
autoscaled; default True. See Axes.autoscale_view for more
451+
information
452+
"""
453+
pass
454+
455+
Note there is a problem for `~matplotlib.artist.Artist` ``__init__`` methods,
456+
e.g., `matplotlib.patches.Patch.__init__`, which supports ``Patch`` ``kwargs``,
457+
since the artist inspector cannot work until the class is fully defined and
458+
we can't modify the ``Patch.__init__.__doc__`` docstring outside the class
459+
definition. There are some some manual hacks in this case, violating the
460+
"single entry point" requirement above -- see the ``docstring.interpd.update``
461+
calls in `matplotlib.patches`.
462+
463463
Inheritance diagrams
464464
====================
465465

0 commit comments

Comments
 (0)
0