Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
matplotlib/doc/sphinxext/gallery_order.py at main · matplotlib/matplotlib · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
matplotlib
matplotlib
Repository navigation
Code
Issues
1.1k
(1.1k)
Pull requests
428
(428)
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
matplotlib
/
doc
/
sphinxext
/
gallery_order.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
175 lines (144 loc) · 5.88 KB
main
Breadcrumbs
matplotlib
/
doc
/
sphinxext
/
gallery_order.py
Copy path
Top
File metadata and controls
Code
Blame
175 lines (144 loc) · 5.88 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
"""
Configuration for the order of gallery sections and examples.
Paths are relative to the conf.py file.
"""
import
itertools
from
pathlib
import
Path
from
sphinx_gallery
.
sorting
import
ExplicitOrder
from
sphinx
.
util
import
logging
as
sphinx_logging
logger
=
sphinx_logging
.
getLogger
(
__name__
)
# Gallery sections shall be displayed in the following order.
# Non-matching sections are inserted at the unsorted position
UNSORTED
=
"unsorted"
examples_order
=
[
# plotting data
'../galleries/examples/lines_bars_and_markers'
,
'../galleries/examples/images_contours_and_fields'
,
'../galleries/examples/statistics'
,
'../galleries/examples/pie_and_polar_charts'
,
# figure, Axes, subplots
'../galleries/examples/subplots_axes_and_figures'
,
# axis properties
'../galleries/examples/ticks'
,
'../galleries/examples/scales'
,
'../galleries/examples/spines'
,
# decorations, individual artists
'../galleries/examples/text_labels_and_annotations'
,
'../galleries/examples/shapes_and_collections'
,
# styling
'../galleries/examples/color'
,
'../galleries/examples/style_sheets'
,
# interfaces / add-ons
'../galleries/examples/pyplots'
,
'../galleries/examples/mplot3d'
,
'../galleries/examples/axes_grid1'
,
'../galleries/examples/axisartist'
,
# animation, interactivity
'../galleries/examples/animation'
,
'../galleries/examples/widgets'
,
'../galleries/examples/event_handling'
,
'../galleries/examples/user_interfaces'
,
UNSORTED
,
'../galleries/examples/misc'
,
# nice and special visualizations
'../galleries/examples/showcase'
,
'../galleries/examples/specialty_plots'
,
]
tutorials_order
=
[
'../galleries/tutorials/introductory'
,
'../galleries/tutorials/intermediate'
,
'../galleries/tutorials/advanced'
,
UNSORTED
,
'../galleries/tutorials/provisional'
]
plot_types_order
=
[
'../galleries/plot_types/basic'
,
'../galleries/plot_types/stats'
,
'../galleries/plot_types/arrays'
,
'../galleries/plot_types/unstructured'
,
'../galleries/plot_types/3D'
,
UNSORTED
]
folder_lists
=
[
examples_order
,
tutorials_order
,
plot_types_order
]
explicit_order_folders
=
[
fd
for
folders
in
folder_lists
for
fd
in
folders
[:
folders
.
index
(
UNSORTED
)]]
explicit_order_folders
.
append
(
UNSORTED
)
explicit_order_folders
.
extend
([
fd
for
folders
in
folder_lists
for
fd
in
folders
[
folders
.
index
(
UNSORTED
):]])
class
MplExplicitOrder
(
ExplicitOrder
):
"""For use within the 'subsection_order' key."""
def
__call__
(
self
,
item
):
"""Return a string determining the sort order."""
if
item
in
self
.
ordered_list
:
return
f"
{
self
.
ordered_list
.
index
(
item
):04d
}
"
else
:
return
f"
{
self
.
ordered_list
.
index
(
UNSORTED
):04d
}
{
item
}
"
class
MplFileExplicitOrder
(
ExplicitOrder
):
"""
An explicit order class that reads the order of examples from 'gallery_order.txt'.
For use with the sphinx_gallery 'within_subsection_order' key.
The file contains a list of example filenames (without the .py extension) in the
desired order, with an optional '*' to indicate where not-listed examples should be
placed.
If '*' is not present, all examples must be listed, or an error will be raised.
Use this if you want to ensure that a full order is intentionally maintained.
"""
def
__init__
(
self
,
src_dir
):
ordered_list
=
self
.
read_gallery_order
(
Path
(
src_dir
).
resolve
())
or
[]
super
().
__init__
(
ordered_list
)
@
staticmethod
def
read_gallery_order
(
src_dir
:
Path
):
"""Return the list of examples to be sorted; read from 'gallery_order.txt'."""
gallery_order_txt
=
src_dir
/
"gallery_order.txt"
if
not
gallery_order_txt
.
exists
():
return
None
lines
=
[
line
.
strip
()
for
line
in
gallery_order_txt
.
read_text
().
splitlines
()
if
line
.
strip
()
and
not
line
.
startswith
(
"#"
)
]
try
:
placeholder_index
=
lines
.
index
(
"*"
)
except
ValueError
:
placeholder_index
=
None
lines
=
[
line
+
".py"
for
line
in
lines
]
if
placeholder_index
is
None
:
front
=
lines
back
=
[]
else
:
front
=
lines
[:
placeholder_index
]
back
=
lines
[
placeholder_index
+
1
:]
listed_examples
=
{
*
front
,
*
back
}
existing_examples
=
{
file
.
name
for
file
in
src_dir
.
iterdir
()
if
file
.
suffix
==
".py"
}
non_existing_examples
=
listed_examples
-
existing_examples
missing_examples
=
existing_examples
-
listed_examples
rel_txt_path
=
gallery_order_txt
.
relative_to
(
gallery_order_txt
.
parents
[
3
])
if
non_existing_examples
:
logger
.
warning
(
f"The following examples listed in
{
rel_txt_path
}
do not exist: "
f"
{
', '
.
join
(
non_existing_examples
)
}
"
)
if
placeholder_index
is
None
and
missing_examples
:
logger
.
warning
(
f"The following examples are not listed in
{
rel_txt_path
}
. "
f"Either include them or add a '*' to indicate where not listed "
f"examples should be placed: "
f"
{
', '
.
join
(
missing_examples
)
}
"
)
mid
=
list
(
sorted
(
missing_examples
))
return
front
+
mid
+
back
def
__call__
(
self
,
item
):
"""Return a string determining the sort order."""
if
not
self
.
ordered_list
:
return
item
return
f"
{
self
.
ordered_list
.
index
(
item
):04d
}
"
def
__repr__
(
self
):
return
'<%s: %s>'
%
(
self
.
__class__
.
__name__
,
self
.
ordered_list
)
# Provide the above classes for use in conf.py
sectionorder
=
MplExplicitOrder
(
explicit_order_folders
)
subsectionorder
=
MplFileExplicitOrder
_preserve_count
=
itertools
.
count
()
def
preserve_order
(
item
):
"""A sorting key to preserve the original order of items in minigalleries."""
return
next
(
_preserve_count
)
You can’t perform that action at this time.