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

Skip to content

Update documentation guide #9805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2017
Merged

Update documentation guide #9805

merged 1 commit into from
Nov 28, 2017

Conversation

dstansby
Copy link
Member

@dstansby dstansby commented Nov 16, 2017

Needs a bit more work, but the aim is to fix #9786 eventually and generally clean the writing documentation guide. Comments very welcome and encouraged! (please also add to the TODO list below)

TODO:

  • Link to numpydoc docs
  • Add section on intersphinx


.. rubric:: Footnotes

.. [#] For example.

* Use the *note* and *warning* directives, sparingly, to draw attention to
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This delted block is covered by numpydoc guidelines


The function `matplotlib.artist.kwdoc` and the decorator
`matplotlib.docstring.dedent_interpd` facilitate this. They combine python
`matplotlib.docstring.dedent_interpd` facilitate this. They combine Python
Copy link
Member

@jklymak jklymak Nov 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the big squak some raised when I tried to use this facilty, should this be in the doc guide?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll still re-iterate that I was told explcitly not to do this for the legend docs a month ago. So if we are not allowed to use this functionality it should be noted here.

@@ -91,244 +90,131 @@ statement, such as::

.. include:: ../../TODO

docstrings
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole section has moved down to the bottom

directories. To exclude the example from having an image rendered,
insert the following special comment anywhere in the script:
automatically included in the HTML docs. To exclude the example from having an
image rendered, insert the following special comment anywhere in the script:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still true @choldgraf ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah no, instead they should put sgskip somewhere in the filename. Maybe worth just noting "all files in the examples directory will be automatically run and rendered into documentation with sphinx-gallery (incl. link)" and leave it at that?


Please do not describe ``argument`` like this.

* Mathematical expressions can be rendered as png images in html, and in the
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the maths, ipython, and footnotes bits, as they are covered in Sphinx documentation, and I don't think they're common enough to need a specific section in the Matplotlib docs.

The documentation sources are found in the :file:`doc/` directory in
the trunk. To build the users guide in html format, cd into
:file:`doc/` and do:
The documentation sources are found in the :file:`doc/` directory in the trunk.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def hlines(self, y, xmin, xmax, colors='k', linestyles='solid',
label='', **kwargs):
"""
Plot horizontal lines at each `y` from `xmin` to `xmax`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be asterisks :p

* Use the *seealso* directive, for example:
Other Parameters
----------------
**kwargs : `~matplotlib.collections.LineCollection` properties.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one space too many after the colon


* Please keep the :ref:`glossary` in mind when writing documentation. You can
create a references to a term in the glossary with the ``:term:`` role.
Please do not describe `argument` like this.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a (short) explanation similar to the one I gave at #9786 (comment) (about the meaning of single backticks) may be helpful.

it via a relative path from the document where the rst file resides, e.g., in
:file:`users/navigation_toolbar.rst`, we refer to the image icons with::
In the documentation, you may want to include to a document in the
Matplotlib src, e.g., a license file or an image file from `mpl-data`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sources

mpl-data directory, I use the symlink directory. For example, from
:file:`customizing.rst`::
In the `users` subdirectory, if you want to refer to a file in the mpl-data
directory, you can use the symlink directory. For example, from
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's a symlink anymore?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

../examples

In master it looks like there still is

@@ -454,7 +287,7 @@ files are duplicated and large)
Internal section references
===========================

To maximize internal consistency in section labeling and references,
To maximize internal consistency in section labelling and references,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

US english one ell? :)

@@ -467,8 +300,8 @@ and refer to it using the standard reference syntax:

See :ref:`howto-webapp`

Keep in mind that we may want to reorganize the contents later, so
let's avoid top level names in references like ``user`` or ``devel``
Keep in mind that we may want to re-organize the contents later, so
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autoscaled; default True. See Axes.autoscale_view for more
information
"""
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the pass is unneeded (syntax is correct without it and it's not the real impl either)

The kwargs are Line2D properties:
%(Line2D)s

kwargs scalex and scaley, if defined, are passed on
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use correct markup (asterisks, backquotes below)

Developer's tips for documenting Matplotlib
===========================================
================================
Developer's tips for documenting
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Documentation guidelines"?

the Sphinx_ documentation generation tool. There are several extra
requirements that are needed to build the documentation. They are listed in
:file:`doc-requirements.txt` as well as listed below:
the Sphinx_ documentation generation tool. There are several extra requirements
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also edited in the Makefile PR

@choldgraf
Copy link
Contributor

@dstansby thanks for cleaning this up! +1 on merge after @anntzer 's comments addressed. feel free to ping me after you do so

generated directories :file:`docs/gallery` and :file:`docs/tutorials` can be
safely deleted.
the directories :file:`docs/gallery` and :file:`docs/tutorials`
are generated.
Copy link
Member

@jklymak jklymak Nov 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say something like: "...are automatically generated. Do not edit the rst files in :file:docs/gallery and :file:docs/tutorials, as they are rebuilt from the sources in the root directory"

I was mystified for a while when my changes to files in these directories were being overwritten ;-)

Matplotlib makes extensive use of keyword arguments as pass-through
arguments, there are a many cases where a table is used in place of a
definition list for autogenerated sections of docstrings.
Please do not describe ``argument`` like this.

Figures
=======

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could use an intoroductory paragraph, or even a change of heading. I find it very mysterious what figures you are talking about. In docstrings? I think you mean in examples and tutorials. If so, maybe a "Writing an example or tutorial" would be a more useful heading, and figure creation is of course the most important thing that happens in that context.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a bit more text and changed the title; is it better now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think maybe a specific section on writing an example/tutorial is needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a new document? This one is quite long already, so sticking to just "Documenting code" is better, and a separate "Writing examples and tutorials" guide can be written.


Plot directive documentation
''''''''''''''''''''''''''''

.. automodule:: matplotlib.sphinxext.plot_directive
:no-undoc-members:

Examples
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above. This seems the heading (+ Tutorials) not "Figures" per se. (I guess there are figures in the numpydocs?)

@@ -492,11 +308,91 @@ For everything but top level chapters, please use ``Upper lower`` for
section titles, e.g., ``Possible hangups`` rather than ``Possible
Hangups``

Setters, getters, and keyword arguments
=======================================
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this way down here instead of up w/ the numpydoc section?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved back up

@dstansby
Copy link
Member Author

dstansby commented Nov 22, 2017

Okay, I think I'm ready for reviews! (ping @choldgraf)

@dstansby dstansby changed the title WIP Update documentating guide Update documentating guide Nov 22, 2017
Add link to numpydoc

Add missing dash

Fix build

Get rid of extra bits

Move setter/getter/kwarg section to near bottom

More cleanup

Remove sections covered in sphinx docs

More small fixes

Correct sgskip

Update title

More cleaning

Move setters/getters/kwargs back

Clarify examples/tutorials directories

Fix code indentation

Improve figure discussion

Improve some headings

Add intersphinx section
@dstansby dstansby changed the title Update documentating guide Update documentation guide Nov 22, 2017
@jklymak
Copy link
Member

jklymak commented Nov 22, 2017


`~matplotlib.collections.LineCollection`

It is also possible to add links to code in Python, Numpy, Scipy, or Pandas.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for example:

.. code-block:: python

numpy.mean

argument the method accepts. e.g., in `.Line2D`:
the `~.matplotlib.artist.Artist` class. The setter methods use the docstring
with the ACCEPTS token to indicate the type of argument the method accepts.
e.g., in `.Line2D`:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I've written some docs, and have used matplotlib for a while. I don't know what the first sentence of this section means. Can we clarify for the somewhat uninitiated?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like

Artist properties are implemented using setter and getter methods (because Matplotlib predates the introductions of the property decorator in Python). By convention, these setters and getters are named set_PROPERTYNAME and get_PROPERTYNAME; the list of properties thusly defined on an artist and their values can be listed by the ~.pyplot.setp and ~.pyplot.getp functions.

Property setter methods should indicate the values they accept using a (legacy) special block in the docstring, starting with ACCEPTS, as follows: (code example follows)

The ACCEPTS block is used to render a table of all properties and their acceptable values in the docs; it can also be displayed using, e.g., plt.setp(Line2D) (all properties) or plt.setp(Line2D, 'linestyle') (just one property).

looks good?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that makes sense to me. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dstansby can you apply the patch? or I can do it too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to push any changes to this section - I don't have the bandwidth to get my head around it at the moment!

Here is a description of *argument*

Please do not use the ```default role```:
Adding figures
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the text below. I'm still not sure about the heading....

@jklymak
Copy link
Member

jklymak commented Nov 22, 2017

General comment: I still think this could use a bit more basic guidance on the different types of documentation at the top. i.e.:

  • ReST files in docs/users and docs/faqs and ?? are translated to html and other downstream formats during the build process.
  • API documentation from docstrings is automatically extracted from the python sources in /lib/matplotlib
  • docs/examples and docs/tutorials are automatically generated from running the python scripts in /examples and /tutorials. Don't edit the generated files!

@tacaswell tacaswell added this to the v2.1.0-doc milestone Nov 23, 2017
@choldgraf
Copy link
Contributor

My 2 cents: I think this should be merged. Even if it is not perfect it is a definite improvement in the documentation, and we've already iterated on this quite a lot. People can always open less ambitious PRs to spot-check things but @dstansby has already done a lot on this PR. Obviously it's their call if they want to keep iterating on comments etc, but let's not let perfect become the enemy of good.

@efiring
Copy link
Member

efiring commented Nov 28, 2017

I'm tempted to follow @choldgraf's advice and merge this, but it looks like @anntzer and/or @jklymak might want to push some quick changes first. Do you?

@jklymak
Copy link
Member

jklymak commented Nov 28, 2017

I think its easier for me to work from master, so I'm happy to put a PR in after this improvement! 👍

@anntzer
Copy link
Contributor

anntzer commented Nov 28, 2017

actually a bit busy today, can anyone prepare a PR from my patch?

@jklymak
Copy link
Member

jklymak commented Nov 28, 2017

Yes, I'll definitely incude your patch. Its very helpful...

@efiring efiring merged commit 2f897dc into matplotlib:master Nov 28, 2017
@lumberbot-app
Copy link

lumberbot-app bot commented Nov 28, 2017

There seem to be a conflict, please backport manually

@dstansby
Copy link
Member Author

Thanks for merging! I was happy to add more changes, but didn't/don't have the time to around now anyway.

@dstansby dstansby deleted the doc-guide branch November 28, 2017 19:35
dstansby pushed a commit to dstansby/matplotlib that referenced this pull request Nov 28, 2017
dstansby added a commit that referenced this pull request Nov 29, 2017
Backport pull request #9805 to v2.1.0-doc
@tacaswell
Copy link
Member

Back port taken care of my 55830e5 merge of v2.1.0-doc in to 2.1.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consistent Documentation Guide for Docstrings
6 participants