Skip to content

DOC: improve tagging guidelines page #28527

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 3 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ help:
clean:
@$(SPHINXBUILD) -M clean "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
rm -rf "$(SOURCEDIR)/build"
rm -rf "$(SOURCEDIR)/_tags"
rm -rf "$(SOURCEDIR)/api/_as_gen"
rm -rf "$(SOURCEDIR)/gallery"
rm -rf "$(SOURCEDIR)/plot_types"
Expand Down
22 changes: 22 additions & 0 deletions doc/_static/mpl.css
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ div.wide-table table th.stub {
display: inline;
}

/* sdd is a custom class that strips out styling from dropdowns
* Example usage:
*
* .. dropdown::
* :class-container: sdd
*
*/

.sdd.sd-dropdown {
box-shadow: none!important;
}
Expand All @@ -185,3 +193,17 @@ div.wide-table table th.stub {
.sdd.sd-dropdown .sd-card-header +.sd-card-body{
--pst-sd-dropdown-color: none;
}

/* section-toc is a custom class that removes the page title from a toctree listing
* Example usage:
*
* .. rst-class:: section-toc
* .. toctree::
*
*/
.section-toc.toctree-wrapper .toctree-l1>a{
display: none;
}
.section-toc.toctree-wrapper li>ul{
padding-inline-start:0;
}
59 changes: 56 additions & 3 deletions doc/devel/document.rst
Original file line number Diff line number Diff line change
Expand Up @@ -894,8 +894,6 @@ these ``*.rst`` files from the source location to the build location (see
In the Python files, to exclude an example from having a plot generated, insert
"sgskip" somewhere in the filename.

Format examples
---------------

The format of these files is relatively straightforward. Properly
formatted comment blocks are treated as ReST_ text, the code is
Expand Down Expand Up @@ -937,7 +935,7 @@ like:
The first comment block is treated as ReST_ text. The other comment blocks
render as comments in :doc:`/gallery/lines_bars_and_markers/simple_plot`.

Tutorials are made with the exact same mechanism, except they are longer, and
Tutorials are made with the exact same mechanism, except they are longer and
typically have more than one comment block (i.e. :ref:`quick_start`). The
first comment block can be the same as the example above. Subsequent blocks of
ReST text are delimited by the line ``# %%`` :
Expand Down Expand Up @@ -1053,6 +1051,61 @@ subdirectory, but :file:`galleries/users_explain/artists` has a mix of
any ``*.rst`` files to a ``:toctree:``, either in the ``README.txt`` or in a
manual ``index.rst``.

Examples guidelines
-------------------

The gallery of examples contains visual demonstrations of matplotlib features. Gallery
examples exist so that users can scan through visual examples. Unlike tutorials or user
guides, gallery examples teach by demonstration, rather than by explanation or
instruction.

Gallery examples should contain a very brief description of *what* is being demonstrated
and, when relevant, *how* it is achieved. Explanations should be brief, providing only
the minimal context necessary for understanding the example. Cross-link related
documentation (e.g. tutorials, user guides and API entries) and tag the example with
related concepts.

Format
^^^^^^

All :ref:`examples-index` should aim to follow these guidelines:

:Title: Describe content in a short sentence (approx. 1-6 words). Do not use *demo* as
Copy link
Member

Choose a reason for hiding this comment

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

Does sentence imply a full sentence including verb? Possible alternatives: expression, phrase ... (not a native speaker so cannot really judge)

this is implied by being an example. Avoid implied verbs such as *create*,
*make*, etc, e.g. *annotated heatmaps* is preferred to *create annotated
heatmaps*. Use the simple present tense when a verb is necessary, e.g. *Fill the
area between two curves*

:Description: In a short paragraph (approx 1-3 sentences) describe what visualization
technique is being demonstrated and how library features are used to
execute the technique, e.g. *Set bar color and bar label entries using the
color and label parameters of ~Axes.bar*

:Plot: Clearly demonstrate the subject and, when possible, show edge cases and different
applications. While the plot should be visually appealing, prioritize keeping the
plot uncluttered.

:Code: Write the minimum necessary to showcase the feature that is the focus of the
example. Avoid custom styling and annotation (titles, legends, colors, etc.)
when it will not improve the clarity of the example.

Use short comments sparingly to describe what hard to follow parts of code are
doing. When more context or explanation is required, add a text paragraph before
the code example.

:doc:`/gallery/misc/bbox_intersect` demonstrates the point of visual examples.
This example is "messy" in that it's hard to categorize, but the gallery is the right
spot for it because it makes sense to find it by visual search

:doc:`/gallery/images_contours_and_fields/colormap_interactive_adjustment` is an
example of a good descriptive title that briefly summarizes how the showcased
library features are used to implement the demonstrated visualization technique.

:doc:`/gallery/lines_bars_and_markers/lines_with_ticks_demo` is an example of having a
minimal amount of code necessary to showcase the feature. The lack of extraneous code
makes it easier for the reader to map which parts of code correspond to which parts of
the plot.

Miscellaneous
=============

Expand Down
24 changes: 16 additions & 8 deletions doc/devel/tag_glossary.rst
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
:orphan:

Tag Glossary
============

I. API tags: what content from the API reference is in the example?
II. Structural tags: what format is the example? What context can we provide?
III. Domain tags: what discipline(s) might seek this example consistently?
IV. Internal tags: what information is helpful for maintainers or contributors?
.. contents::
:depth: 1
:local:
:backlinks: entry


API tags: what content from the API reference is in the example?
----------------------------------------------------------------

+-----------------------------------+---------------------------------------------+
|``tag`` | use case - if not obvious |
|``tag`` | use case |
+===================================+=============================================+
|**Primary or relevant plot component** |
+-----------------------------------+---------------------------------------------+
Expand Down Expand Up @@ -142,7 +140,9 @@ Structural tags: what format is the example? What context can we provide?
Domain tags: what discipline(s) might seek this example consistently?
---------------------------------------------------------------------

It's futile to draw fences around "who owns what", and that's not the point of domain tags. Domain tags help groups of people to privately organize relevant information, and so are not displayed publicly. See below for a list of existing domain tags. If you don't see the one you're looking for and you think it should exist, consider proposing it.
It's futile to draw fences around "who owns what", and that's not the point of domain
tags. See below for a list of existing domain tags. If you don't see the one you're
looking for and you think it should exist, consider proposing it.

+-------------------------------+----------------------------------------+
|``tag`` | use case |
Expand All @@ -163,6 +163,14 @@ It's futile to draw fences around "who owns what", and that's not the point of d
Internal tags: what information is helpful for maintainers or contributors?
---------------------------------------------------------------------------

These tags should be used only for development purposes; therefore please add them
separately behind a version guard:

.. code:: rst

.. ifconfig:: releaselevel == 'dev'
.. tags:: internal: needs-review

+-------------------------------+-----------------------------------------------------------------------+
|``tag`` | use case |
+===============================+=======================================================================+
Expand Down
89 changes: 42 additions & 47 deletions doc/devel/tag_guidelines.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
Guidelines for assigning tags to gallery examples
=================================================
Tagging guidelines
==================

Why do we need tags?
--------------------

Tags serve multiple purposes.

Tags have a one-to-many organization (i.e. one example can have several tags), while the gallery structure requires that examples are placed in only one location. This means tags provide a secondary layer of organization and make the gallery of examples more flexible and more user-friendly.
Tags have a one-to-many organization (i.e. one example can have several tags), while
the gallery structure requires that examples are placed in only one location. This means
tags provide a secondary layer of organization and make the gallery of examples more
flexible and more user-friendly.

They allow for better discoverability, search, and browse functionality. They are helpful for users struggling to write a search query for what they're looking for.
They allow for better discoverability, search, and browse functionality. They are
helpful for users struggling to write a search query for what they're looking for.

Hidden tags provide additional functionality for maintainers and contributors.

How to tag?
-----------
Place the tag directive at the bottom of each page and add the tags underneath, e.g.:

.. code-block:: rst

.. tags::
topic: tagging, purpose: reference

What gets a tag?
----------------

Expand All @@ -20,56 +33,38 @@ Every gallery example should be tagged with:
* 1+ content tags
* structural, domain, or internal tag(s) if helpful

Tags can repeat existing forms of organization (e.g. an example is in the Animation folder and also gets an ``animation`` tag).
Tags can repeat existing forms of organization (e.g. an example is in the Animation
folder and also gets an ``animation`` tag).

Tags are helpful to denote particularly good "byproduct" examples. E.g. the explicit
purpose of a gallery example might be to demonstrate a colormap, but it's also a good
demonstration of a legend. Tag ``legend`` to indicate that, rather than changing the
title or the scope of the example.

Tags are helpful to denote particularly good "byproduct" examples. E.g. the explicit purpose of a gallery example might be to demonstrate a colormap, but it's also a good demonstration of a legend. Tag ``legend`` to indicate that, rather than changing the title or the scope of the example.
.. card::

**Tag Categories** - See :doc:`Tag Glossary <tag_glossary>` for a complete list of tags.
**Tag Categories**
^^^
.. rst-class:: section-toc

I. API tags: what content from the API reference is in the example?
II. Structural tags: what format is the example? What context can we provide?
III. Domain tags: what discipline(s) might seek this example consistently?
IV. Internal tags: what information is helpful for maintainers or contributors?
.. toctree::
:maxdepth: 2

tag_glossary

+++
See :doc:`Tag Glossary <tag_glossary>` for a complete list

Proposing new tags
------------------

1. Review existing tag list, looking out for similar entries (i.e. ``axes`` and ``axis``).
2. If a relevant tag or subcategory does not yet exist, propose it. Each tag is two parts: ``subcategory: tag``. Tags should be one or two words.
3. New tags should be be added when they are relevant to existing gallery entries too. Avoid tags that will link to only a single gallery entry.
2. If a relevant tag or subcategory does not yet exist, propose it. Each tag is two
parts: ``subcategory: tag``. Tags should be one or two words.
3. New tags should be be added when they are relevant to existing gallery entries too.
Avoid tags that will link to only a single gallery entry.
4. Tags can recreate other forms of organization.

Note: Tagging organization aims to work for 80-90% of cases. Some examples fall outside of the tagging structure. Niche or specific examples shouldn't be given standalone tags that won't apply to other examples.

How to tag?
-----------
Put each tag as a directive at the bottom of the page.

Related content
---------------

What is a gallery example?
^^^^^^^^^^^^^^^^^^^^^^^^^^

The gallery of examples contains visual demonstrations of matplotlib features. Gallery examples exist so that users can scan through visual examples.

Unlike tutorials or user guides, gallery examples teach by demonstration, rather than by explanation or instruction.

Gallery examples should avoid instruction or excessive explanation except for brief clarifying code comments. Instead, they can tag related concepts and/or link to relevant tutorials or user guides.

Format
^^^^^^

All :ref:`examples-index` should aim to follow the following format:

* Title: 1-6 words, descriptive of content
* Subtitle: 10-50 words, action-oriented description of the example subject
* Image: a clear demonstration of the subject, showing edge cases and different applications if possible
* Code + Text (optional): code, commented as appropriate + written text to add context if necessary

Example:

The ``bbox_intersect`` gallery example demonstrates the point of visual examples:

* this example is "messy" in that it's hard to categorize, but the gallery is the right spot for it because it makes sense to find it by visual search
* https://matplotlib.org/devdocs/gallery/misc/bbox_intersect.html#sphx-glr-gallery-misc-bbox-intersect-py
Tagging organization aims to work for 80-90% of cases. Some examples fall outside of the
tagging structure. Niche or specific examples shouldn't be given standalone tags that
won't apply to other examples.
1 change: 1 addition & 0 deletions doc/make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ if "%1" == "show" goto show
if "%1" == "clean" (
REM workaround because sphinx does not completely clean up (#11139)
rmdir /s /q "%SOURCEDIR%\build"
rmdir /s /q "%SOURCEDIR%\_tags"
rmdir /s /q "%SOURCEDIR%\api\_as_gen"
rmdir /s /q "%SOURCEDIR%\gallery"
rmdir /s /q "%SOURCEDIR%\plot_types"
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies:
- sphinx-copybutton
- sphinx-gallery>=0.12.0
- sphinx-design
- sphinx-tags>=0.3.0
- sphinx-tags>=0.4.0
- pip
- pip:
- mpl-sphinx-theme~=3.8.0
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ ignore_directives = [
# sphinxext.redirect_from
"redirect-from",
# sphinx-design
"card",
"dropdown",
"grid",
"tab-set",
Expand All @@ -279,6 +280,8 @@ ignore_directives = [
"ifconfig",
# sphinx.ext.inheritance_diagram
"inheritance-diagram",
# sphinx-tags
"tags",
# include directive is causing attribute errors
"include"
]
Expand Down
2 changes: 1 addition & 1 deletion requirements/doc/doc-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ sphinxcontrib-svg2pdfconverter>=1.1.0
sphinx-copybutton
sphinx-design
sphinx-gallery>=0.12.0
sphinx-tags>=0.3.0
sphinx-tags>=0.4.0
Loading