Skip to content

Commit 750793c

Browse files
committed
PoC: Document each rcParam individually
Taking cues from the math symbol table, this adds a directive to generate a listing from the `RcParams` dictionary, with types taken from the validators (partially complete), though there could perhaps be other ways to implement it. Then the `rc` role is updated to point to these individual anchors. We also have nowhere to put the documentation for each one yet, so the actual information is all just stubs.
1 parent cf84d9a commit 750793c

File tree

5 files changed

+208
-125
lines changed

5 files changed

+208
-125
lines changed

doc/conf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ def _parse_skip_subdirs_file():
124124
'sphinxext.math_symbol_table',
125125
'sphinxext.missing_references',
126126
'sphinxext.mock_gui_toolkits',
127-
'sphinxext.skip_deprecated',
127+
'sphinxext.rcparams',
128128
'sphinxext.redirect_from',
129+
'sphinxext.skip_deprecated',
129130
'sphinx_copybutton',
130131
'sphinx_design',
131132
'sphinx_tags',

doc/sphinxext/rcparams.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import enum
2+
3+
from docutils.parsers.rst import Directive
4+
5+
from matplotlib import rcParams, rcParamsDefault, rcsetup
6+
7+
8+
def determine_type(validator):
9+
if isinstance(validator, enum.EnumType):
10+
return f'`~._enums.{validator.__name__}`'
11+
elif docstr := getattr(validator, '__doc__'):
12+
return docstr
13+
else:
14+
return str(validator)
15+
16+
17+
def run(state_machine):
18+
lines = []
19+
current_section = None
20+
for rc in sorted(rcParams.keys()):
21+
if rc[0] == '_':
22+
continue
23+
24+
# This would be much easier with #25617.
25+
section = rc.rsplit('.', maxsplit=1)[0]
26+
if section != current_section:
27+
lines.append(f'.. _rc-{section}:')
28+
current_section = section
29+
30+
type_str = determine_type(rcsetup._validators[rc])
31+
if rc in rcParamsDefault and rc != "backend":
32+
default = f', default: {rcParamsDefault[rc]!r}'
33+
else:
34+
default = ''
35+
lines += [
36+
f'.. _rc-{rc}:',
37+
'',
38+
rc,
39+
'^' * len(rc),
40+
f'{type_str}{default}',
41+
f' Documentation for {rc}.'
42+
]
43+
state_machine.insert_input(lines, "rcParams table")
44+
return []
45+
46+
47+
class RcParamsDirective(Directive):
48+
has_content = False
49+
required_arguments = 0
50+
optional_arguments = 0
51+
final_argument_whitespace = False
52+
option_spec = {}
53+
54+
def run(self):
55+
return run(self.state_machine)
56+
57+
58+
def setup(app):
59+
app.add_directive("rcparams", RcParamsDirective)
60+
61+
metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
62+
return metadata

galleries/users_explain/customizing.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ def plotting_function():
108108
# ignored in style sheets see `matplotlib.style.use`.
109109
#
110110
# There are a number of pre-defined styles :doc:`provided by Matplotlib
111-
# </gallery/style_sheets/style_sheets_reference>`. For
112-
# example, there's a pre-defined style called "ggplot", which emulates the
113-
# aesthetics of ggplot_ (a popular plotting package for R_). To use this
114-
# style, add:
111+
# </gallery/style_sheets/style_sheets_reference>`. For example, there's a pre-defined
112+
# style called "ggplot", which emulates the aesthetics of `ggplot
113+
# <https://ggplot2.tidyverse.org/>`_ (a popular plotting package for `R
114+
# <https://www.r-project.org/>`_). To use this style, add:
115115

116116
plt.style.use('ggplot')
117117

@@ -259,11 +259,10 @@ def plotting_function():
259259
#
260260
# .. _matplotlibrc-sample:
261261
#
262-
# The default :file:`matplotlibrc` file
263-
# -------------------------------------
262+
# Available ``rcParams``
263+
# ----------------------
264264
#
265-
# .. literalinclude:: ../../../lib/matplotlib/mpl-data/matplotlibrc
265+
#
266+
# .. rcparams::
266267
#
267268
#
268-
# .. _ggplot: https://ggplot2.tidyverse.org/
269-
# .. _R: https://www.r-project.org/

0 commit comments

Comments
 (0)