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

Skip to content

Commit d0f0a21

Browse files
story645esibingatimhoffm
committed
use glossery headings for category listings
add coding example move content guidelines to writing guide enable multiline Co-authored-by: Eva Sibinga <[email protected]> Co-authored-by: Tim Hoffmann <[email protected]>
1 parent c0071b8 commit d0f0a21

File tree

7 files changed

+135
-60
lines changed

7 files changed

+135
-60
lines changed

doc/_static/mpl.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ div.wide-table table th.stub {
167167
display: inline;
168168
}
169169

170+
/*sdd is a custom class that strips out styling from dropdowns
171+
* Example usage:
172+
*
173+
* .. dropdown::
174+
:class-container: sdd
175+
*/
176+
170177
.sdd.sd-dropdown {
171178
box-shadow: none!important;
172179
}
@@ -185,3 +192,17 @@ div.wide-table table th.stub {
185192
.sdd.sd-dropdown .sd-card-header +.sd-card-body{
186193
--pst-sd-dropdown-color: none;
187194
}
195+
196+
/* section-toc is a custom class that removes the page title from a toctree listing
197+
* Example usage:
198+
*
199+
* .. rst-class:: section-toc
200+
*
201+
* .. toctree::
202+
*/
203+
.section-toc.toctree-wrapper .toctree-l1>a{
204+
display: none;
205+
}
206+
.section-toc.toctree-wrapper li>ul{
207+
padding-inline-start:0;
208+
}

doc/devel/document.rst

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -894,8 +894,6 @@ these ``*.rst`` files from the source location to the build location (see
894894
In the Python files, to exclude an example from having a plot generated, insert
895895
"sgskip" somewhere in the filename.
896896

897-
Format examples
898-
---------------
899897

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

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

1054+
Examples guidelines
1055+
-------------------
1056+
1057+
The gallery of examples contains visual demonstrations of matplotlib features. Gallery
1058+
examples exist so that users can scan through visual examples. Unlike tutorials or user
1059+
guides, gallery examples teach by demonstration, rather than by explanation or
1060+
instruction.
1061+
1062+
Gallery examples should contain a very brief description of *what* they demonstrate and,
1063+
when relevant, *how* it is achieved. Avoid instructions or excessive explanation;
1064+
instead, tag with related concepts and cross-link to relevant tutorials or user guides.
1065+
1066+
Format
1067+
^^^^^^
1068+
1069+
All :ref:`examples-index` should aim to follow these guidelines:
1070+
1071+
:Title: Describe content in a short sentence (approx. 1-6 words). Do not use *demo* as
1072+
this is implied by being an example. Avoid implied verbs such as "creating,
1073+
making, etc", e.g. "annotated heatmaps" is preferred to "creating annotated
1074+
heatmaps". Use the simple present tense when a verb is necessary, e.g. *Fill the
1075+
area between two curves*
1076+
1077+
:Subtitle: In a short paragraph (approx 1-3 sentences) describe what visualization
1078+
technique is being demonstrated and how library features are used to execute
1079+
the technique, e.g. *Set bar color and bar label entries using the color and
1080+
label parameters of ~Axes.bar*
1081+
1082+
:Plot: Clearly demonstrate the subject and, when possible, show edge cases and different
1083+
applications. While the plot should be visually appealing, prioritize keeping the
1084+
plot uncluttered.
1085+
1086+
:Code: Write the minimum necessary to showcase the feature that is the focus of the
1087+
example. Avoid styling and annotation-such as setting titles, legends, colors,
1088+
etc.- when it will not improve the clarity of the example.
1089+
1090+
:Text: Use short comments sparingly to describe what hard to follow parts of code are
1091+
doing. When more context or explanation is required, add a text paragraph before
1092+
the code example.
1093+
1094+
Example:
1095+
1096+
The ``bbox_intersect`` gallery example demonstrates the point of visual examples:
1097+
1098+
* this example is "messy" in that it's hard to categorize, but the gallery is the right
1099+
spot for it because it makes sense to find it by visual search
1100+
* https://matplotlib.org/devdocs/gallery/misc/bbox_intersect.html#sphx-glr-gallery-misc-bbox-intersect-py
1101+
10561102
Miscellaneous
10571103
=============
10581104

doc/devel/tag_glossary.rst

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
:orphan:
2-
31
Tag Glossary
42
============
53

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

119

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

1513
+-----------------------------------+---------------------------------------------+
16-
|``tag`` | use case - if not obvious |
14+
|``tag`` | use case |
1715
+===================================+=============================================+
1816
|**Primary or relevant plot component** |
1917
+-----------------------------------+---------------------------------------------+
@@ -142,7 +140,9 @@ Structural tags: what format is the example? What context can we provide?
142140
Domain tags: what discipline(s) might seek this example consistently?
143141
---------------------------------------------------------------------
144142

145-
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.
143+
It's futile to draw fences around "who owns what", and that's not the point of domain
144+
tags. See below for a list of existing domain tags. If you don't see the one you're
145+
looking for and you think it should exist, consider proposing it.
146146

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

166+
These tags should be used only for development purposes; therefore please add them
167+
separately behind a version guard:
168+
169+
.. code:: rst
170+
171+
.. ifconfig:: releaselevel == 'dev'
172+
.. tags:: internal: needs-review
173+
166174
+-------------------------------+-----------------------------------------------------------------------+
167175
|``tag`` | use case |
168176
+===============================+=======================================================================+

doc/devel/tag_guidelines.rst

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
1-
Guidelines for assigning tags to gallery examples
2-
=================================================
1+
Tagging guidelines
2+
==================
33

44
Why do we need tags?
55
--------------------
66

77
Tags serve multiple purposes.
88

9-
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.
9+
Tags have a one-to-many organization (i.e. one example can have several tags), while
10+
the gallery structure requires that examples are placed in only one location. This means
11+
tags provide a secondary layer of organization and make the gallery of examples more
12+
flexible and more user-friendly.
1013

11-
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.
14+
They allow for better discoverability, search, and browse functionality. They are
15+
helpful for users struggling to write a search query for what they're looking for.
1216

1317
Hidden tags provide additional functionality for maintainers and contributors.
1418

19+
How to tag?
20+
-----------
21+
Place the tag directive at the bottom of each page and add the tags underneath
22+
23+
.. code-block:: python
24+
25+
# fig, ax = plt.subplots()
26+
# ax.plot([1,2,3], [3,2,1], linestyle=':')
27+
#
28+
# .. tags::
29+
# plot-type: line, styling: texture,
30+
31+
1532
What gets a tag?
1633
----------------
1734

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

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

25-
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.
43+
Tags are helpful to denote particularly good "byproduct" examples. E.g. the explicit
44+
purpose of a gallery example might be to demonstrate a colormap, but it's also a good
45+
demonstration of a legend. Tag ``legend`` to indicate that, rather than changing the
46+
title or the scope of the example.
2647

27-
**Tag Categories** - See :doc:`Tag Glossary <tag_glossary>` for a complete list of tags.
48+
.. card::
2849

29-
I. API tags: what content from the API reference is in the example?
30-
II. Structural tags: what format is the example? What context can we provide?
31-
III. Domain tags: what discipline(s) might seek this example consistently?
32-
IV. Internal tags: what information is helpful for maintainers or contributors?
50+
**Tag Categories**
51+
^^^
52+
.. rst-class:: section-toc
53+
54+
.. toctree::
55+
:maxdepth: 2
56+
57+
tag_glossary
58+
59+
+++
60+
See :doc:`Tag Glossary <tag_glossary>` for a complete list
3361

3462
Proposing new tags
3563
------------------
3664

3765
1. Review existing tag list, looking out for similar entries (i.e. ``axes`` and ``axis``).
38-
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.
39-
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.
66+
2. If a relevant tag or subcategory does not yet exist, propose it. Each tag is two
67+
parts: ``subcategory: tag``. Tags should be one or two words.
68+
3. New tags should be be added when they are relevant to existing gallery entries too.
69+
Avoid tags that will link to only a single gallery entry.
4070
4. Tags can recreate other forms of organization.
4171

42-
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.
43-
44-
How to tag?
45-
-----------
46-
Put each tag as a directive at the bottom of the page.
47-
48-
Related content
49-
---------------
50-
51-
What is a gallery example?
52-
^^^^^^^^^^^^^^^^^^^^^^^^^^
53-
54-
The gallery of examples contains visual demonstrations of matplotlib features. Gallery examples exist so that users can scan through visual examples.
55-
56-
Unlike tutorials or user guides, gallery examples teach by demonstration, rather than by explanation or instruction.
57-
58-
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.
59-
60-
Format
61-
^^^^^^
62-
63-
All :ref:`examples-index` should aim to follow the following format:
64-
65-
* Title: 1-6 words, descriptive of content
66-
* Subtitle: 10-50 words, action-oriented description of the example subject
67-
* Image: a clear demonstration of the subject, showing edge cases and different applications if possible
68-
* Code + Text (optional): code, commented as appropriate + written text to add context if necessary
69-
70-
Example:
71-
72-
The ``bbox_intersect`` gallery example demonstrates the point of visual examples:
73-
74-
* 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
75-
* https://matplotlib.org/devdocs/gallery/misc/bbox_intersect.html#sphx-glr-gallery-misc-bbox-intersect-py
72+
Tagging organization aims to work for 80-90% of cases. Some examples fall outside of the
73+
tagging structure. Niche or specific examples shouldn't be given standalone tags that
74+
won't apply to other examples.

environment.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ dependencies:
4040
- sphinx-copybutton
4141
- sphinx-gallery>=0.12.0
4242
- sphinx-design
43-
- sphinx-tags>=0.3.0
43+
- sphinx-tags>=0.4.0
4444
- pip
4545
- pip:
4646
- mpl-sphinx-theme~=3.8.0

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ ignore_directives = [
259259
# sphinxext.redirect_from
260260
"redirect-from",
261261
# sphinx-design
262+
"card",
262263
"dropdown",
263264
"grid",
264265
"tab-set",

requirements/doc/doc-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ sphinxcontrib-svg2pdfconverter>=1.1.0
2121
sphinx-copybutton
2222
sphinx-design
2323
sphinx-gallery>=0.12.0
24-
sphinx-tags>=0.3.0
24+
sphinx-tags>=0.4.0

0 commit comments

Comments
 (0)