Skip to content

Commit 502b311

Browse files
authored
Merge pull request matplotlib#27200 from timhoffm/doc-type-ref
DOC: Add role for custom informal types like color
2 parents 2ea5c58 + 689ab84 commit 502b311

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

doc/sphinxext/custom_roles.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,23 @@ def rcparam_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
6464
return node_list, messages
6565

6666

67+
def mpltype_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
68+
mpltype = text
69+
type_to_link_target = {
70+
'color': 'colors_def',
71+
}
72+
if mpltype not in type_to_link_target:
73+
raise ValueError(f"Unknown mpltype: {mpltype!r}")
74+
75+
ref_nodes, messages = inliner.interpreted(
76+
mpltype, f'{mpltype} <{type_to_link_target[mpltype]}>', 'ref', lineno)
77+
node_list = [ref_nodes]
78+
return node_list, messages
79+
80+
6781
def setup(app):
6882
app.add_role("rc", rcparam_role)
83+
app.add_role("mpltype", mpltype_role)
6984
app.add_node(
7085
QueryReference,
7186
html=(visit_query_reference_node, depart_query_reference_node),

lib/matplotlib/widgets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def __init__(self, ax, label, image=None,
191191
image : array-like or PIL Image
192192
The image to place in the button, if not *None*. The parameter is
193193
directly forwarded to `~.axes.Axes.imshow`.
194-
color : color
194+
color : :mpltype:`color`
195195
The color of the button when not activated.
196196
hovercolor : color
197197
The color of the button when the mouse is over it.

0 commit comments

Comments
 (0)