Skip to content

Commit 44a9036

Browse files
authored
Merge pull request #10226 from anntzer/rc-role
Custom :rcparam: role.
2 parents c09f726 + 0c9fddf commit 44a9036

File tree

12 files changed

+231
-232
lines changed

12 files changed

+231
-232
lines changed

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
'sphinx.ext.inheritance_diagram', 'sphinx.ext.intersphinx',
3636
'sphinx_gallery.gen_gallery',
3737
'matplotlib.sphinxext.plot_directive',
38-
'sphinxext.github',
38+
'sphinxext.github', 'sphinxext.custom_roles',
3939
'numpydoc']
4040

4141
exclude_patterns = ['api/api_changes/*', 'users/whats_new/*']

doc/devel/MEP/MEP23.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@ Sometimes when there are too many figures open at the same time, it is
3737
desirable to be able to group these under the same window
3838
[see](https://github.com/matplotlib/matplotlib/issues/2194).
3939

40-
The proposed solution modifies `FigureManagerBase` to contain and
41-
manage more than one `canvas`. The settings parameter
42-
`rcParams['backend.multifigure']` control when the **MultiFigure**
43-
behaviour is desired.
40+
The proposed solution modifies `FigureManagerBase` to contain and manage more
41+
than one `canvas`. The settings parameter :rc:`backend.multifigure` control
42+
when the **MultiFigure** behaviour is desired.
4443

4544
**Note**
4645

doc/devel/documenting_mpl.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,14 +410,15 @@ to keep in mind:
410410
-------
411411
lines : `~matplotlib.collections.LineCollection`
412412
413+
* rcParams can be referenced with the custom ``:rc:`` role:
414+
:literal:`:rc:\`foo\`` yields ``rcParams["foo"]``.
413415

414416
Deprecated formatting conventions
415417
---------------------------------
416418
* Formerly, we have used square brackets for explicit parameter lists
417419
``['solid' | 'dashed' | 'dotted']``. With numpydoc we have switched to their
418420
standard using curly braces ``{'solid', 'dashed', 'dotted'}``.
419421

420-
421422
Linking to other code
422423
---------------------
423424
To link to other methods, classes, or modules in Matplotlib you can encase

doc/sphinxext/custom_roles.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from docutils import nodes
2+
3+
4+
def rcparam_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
5+
rendered = nodes.Text('rcParams["{}"]'.format(text))
6+
return [nodes.literal(rawtext, rendered)], []
7+
8+
9+
def setup(app):
10+
app.add_role("rc", rcparam_role)
11+
return {"parallel_read_safe": True, "parallel_write_safe": True}

lib/matplotlib/animation.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,32 +1051,31 @@ def save(self, filename, writer=None, fps=None, dpi=None, codec=None,
10511051
writer : :class:`MovieWriter` or str, optional
10521052
A `MovieWriter` instance to use or a key that identifies a
10531053
class to use, such as 'ffmpeg'. If ``None``, defaults to
1054-
``rcParams['animation.writer']``.
1054+
:rc:`animation.writer`.
10551055
10561056
fps : number, optional
10571057
Frames per second in the movie. Defaults to ``None``, which will use
10581058
the animation's specified interval to set the frames per second.
10591059
10601060
dpi : number, optional
1061-
Controls the dots per inch for the movie frames. This
1062-
combined with the figure's size in inches controls the size of
1063-
the movie. If ``None``, defaults to ``rcparam['savefig.dpi']``.
1061+
Controls the dots per inch for the movie frames. This combined with
1062+
the figure's size in inches controls the size of the movie. If
1063+
``None``, defaults to :rc:`savefig.dpi`.
10641064
10651065
codec : str, optional
1066-
The video codec to be used. Not all codecs are supported by
1067-
a given :class:`MovieWriter`. If ``None``,
1068-
default to ``rcParams['animation.codec']``.
1066+
The video codec to be used. Not all codecs are supported
1067+
by a given :class:`MovieWriter`. If ``None``, default to
1068+
:rc:`animation.codec`.
10691069
10701070
bitrate : number, optional
10711071
Specifies the number of bits used per second in the compressed
10721072
movie, in kilobits per second. A higher number means a higher
10731073
quality movie, but at the cost of increased file size. If ``None``,
1074-
defaults to ``rcParam['animation.bitrate']``.
1074+
defaults to :rc:`animation.bitrate`.
10751075
10761076
extra_args : list, optional
1077-
List of extra string arguments to be passed to the
1078-
underlying movie utility. If ``None``, defaults to
1079-
``rcParams['animation.extra_args']``
1077+
List of extra string arguments to be passed to the underlying movie
1078+
utility. If ``None``, defaults to :rc:`animation.extra_args`.
10801079
10811080
metadata : Dict[str, str], optional
10821081
Dictionary of keys and values for metadata to include in

lib/matplotlib/axes/_axes.py

Lines changed: 52 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -411,27 +411,27 @@ def legend(self, *args, **kwargs):
411411
412412
numpoints : None or int
413413
The number of marker points in the legend when creating a legend
414-
entry for a line/:class:`matplotlib.lines.Line2D`.
415-
Default is ``None`` which will take the value from the
416-
``legend.numpoints`` :data:`rcParam<matplotlib.rcParams>`.
414+
entry for a `~.Line2D` (line).
415+
Default is ``None``, which will take the value from
416+
:rc:`legend.numpoints`.
417417
418418
scatterpoints : None or int
419-
The number of marker points in the legend when creating a legend
420-
entry for a scatter plot/
421-
:class:`matplotlib.collections.PathCollection`.
422-
Default is ``None`` which will take the value from the
423-
``legend.scatterpoints`` :data:`rcParam<matplotlib.rcParams>`.
419+
The number of marker points in the legend when creating
420+
a legend entry for a `~.PathCollection` (scatter plot).
421+
Default is ``None``, which will take the value from
422+
:rc:`legend.scatterpoints`.
424423
425424
scatteryoffsets : iterable of floats
426425
The vertical offset (relative to the font size) for the markers
427426
created for a scatter plot legend entry. 0.0 is at the base the
428427
legend text, and 1.0 is at the top. To draw all markers at the
429-
same height, set to ``[0.5]``. Default ``[0.375, 0.5, 0.3125]``.
428+
same height, set to ``[0.5]``. Default is ``[0.375, 0.5, 0.3125]``.
430429
431430
markerscale : None or int or float
432431
The relative size of legend markers compared with the originally
433-
drawn ones. Default is ``None`` which will take the value from
434-
the ``legend.markerscale`` :data:`rcParam <matplotlib.rcParams>`.
432+
drawn ones.
433+
Default is ``None``, which will take the value from
434+
:rc:`legend.markerscale`.
435435
436436
markerfirst : bool
437437
If *True*, legend marker is placed to the left of the legend label.
@@ -440,42 +440,40 @@ def legend(self, *args, **kwargs):
440440
Default is *True*.
441441
442442
frameon : None or bool
443-
Control whether the legend should be drawn on a patch (frame).
444-
Default is ``None`` which will take the value from the
445-
``legend.frameon`` :data:`rcParam<matplotlib.rcParams>`.
443+
Control whether the legend should be drawn on a patch
444+
(frame).
445+
Default is ``None``, which will take the value from
446+
:rc:`legend.frameon`.
446447
447448
fancybox : None or bool
448-
Control whether round edges should be enabled around
449-
the :class:`~matplotlib.patches.FancyBboxPatch` which
450-
makes up the legend's background.
451-
Default is ``None`` which will take the value from the
452-
``legend.fancybox`` :data:`rcParam<matplotlib.rcParams>`.
449+
Control whether round edges should be enabled around the
450+
:class:`~matplotlib.patches.FancyBboxPatch` which makes up the
451+
legend's background.
452+
Default is ``None``, which will take the value from
453+
:rc:`legend.fancybox`.
453454
454455
shadow : None or bool
455456
Control whether to draw a shadow behind the legend.
456-
Default is ``None`` which will take the value from the
457-
``legend.shadow`` :data:`rcParam<matplotlib.rcParams>`.
457+
Default is ``None``, which will take the value from
458+
:rc:`legend.shadow`.
458459
459460
framealpha : None or float
460461
Control the alpha transparency of the legend's background.
461-
Default is ``None`` which will take the value from the
462-
``legend.framealpha`` :data:`rcParam<matplotlib.rcParams>`.
463-
If shadow is activated and framealpha is ``None`` the
464-
default value is being ignored.
462+
Default is ``None``, which will take the value from
463+
:rc:`legend.framealpha`. If shadow is activated and
464+
*framealpha* is ``None``, the default value is ignored.
465465
466466
facecolor : None or "inherit" or a color spec
467467
Control the legend's background color.
468-
Default is ``None`` which will take the value from the
469-
``legend.facecolor`` :data:`rcParam<matplotlib.rcParams>`.
470-
If ``"inherit"``, it will take the ``axes.facecolor``
471-
:data:`rcParam<matplotlib.rcParams>`.
468+
Default is ``None``, which will take the value from
469+
:rc:`legend.facecolor`. If ``"inherit"``, it will take
470+
:rc:`axes.facecolor`.
472471
473472
edgecolor : None or "inherit" or a color spec
474473
Control the legend's background patch edge color.
475-
Default is ``None`` which will take the value from the
476-
``legend.edgecolor`` :data:`rcParam<matplotlib.rcParams>`.
477-
If ``"inherit"``, it will take the ``axes.edgecolor``
478-
:data:`rcParam<matplotlib.rcParams>`.
474+
Default is ``None``, which will take the value from
475+
:rc:`legend.edgecolor` If ``"inherit"``, it will take
476+
:rc:`axes.edgecolor`.
479477
480478
mode : {"expand", None}
481479
If `mode` is set to ``"expand"`` the legend will be horizontally
@@ -493,38 +491,38 @@ def legend(self, *args, **kwargs):
493491
borderpad : float or None
494492
The fractional whitespace inside the legend border.
495493
Measured in font-size units.
496-
Default is ``None`` which will take the value from the
497-
``legend.borderpad`` :data:`rcParam<matplotlib.rcParams>`.
494+
Default is ``None``, which will take the value from
495+
:rc:`legend.borderpad`.
498496
499497
labelspacing : float or None
500498
The vertical space between the legend entries.
501499
Measured in font-size units.
502-
Default is ``None`` which will take the value from the
503-
``legend.labelspacing`` :data:`rcParam<matplotlib.rcParams>`.
500+
Default is ``None``, which will take the value from
501+
:rc:`legend.labelspacing`.
504502
505503
handlelength : float or None
506504
The length of the legend handles.
507505
Measured in font-size units.
508-
Default is ``None`` which will take the value from the
509-
``legend.handlelength`` :data:`rcParam<matplotlib.rcParams>`.
506+
Default is ``None``, which will take the value from
507+
:rc:`legend.handlelength`.
510508
511509
handletextpad : float or None
512510
The pad between the legend handle and text.
513511
Measured in font-size units.
514-
Default is ``None`` which will take the value from the
515-
``legend.handletextpad`` :data:`rcParam<matplotlib.rcParams>`.
512+
Default is ``None``, which will take the value from
513+
:rc:`legend.handletextpad`.
516514
517515
borderaxespad : float or None
518516
The pad between the axes and legend border.
519517
Measured in font-size units.
520-
Default is ``None`` which will take the value from the
521-
``legend.borderaxespad`` :data:`rcParam<matplotlib.rcParams>`.
518+
Default is ``None``, which will take the value from
519+
:rc:`legend.borderaxespad`.
522520
523521
columnspacing : float or None
524522
The spacing between columns.
525523
Measured in font-size units.
526-
Default is ``None`` which will take the value from the
527-
``legend.columnspacing`` :data:`rcParam<matplotlib.rcParams>`.
524+
Default is ``None``, which will take the value from
525+
:rc:`legend.columnspacing`.
528526
529527
handler_map : dict or None
530528
The custom dictionary mapping instances or types to a legend
@@ -2058,8 +2056,8 @@ def bar(self, *args, **kwargs):
20582056
20592057
capsize : scalar, optional
20602058
The length of the error bar caps in points.
2061-
Default: None, which will take the value from the
2062-
``errorbar.capsize`` :data:`rcParam<matplotlib.rcParams>`.
2059+
Default: None, which will take the value from
2060+
:rc:`errorbar.capsize`.
20632061
20642062
error_kw : dict, optional
20652063
Dictionary of kwargs to be passed to the `~.Axes.errorbar`
@@ -2376,8 +2374,8 @@ def barh(self, *args, **kwargs):
23762374
23772375
capsize : scalar, optional
23782376
The length of the error bar caps in points.
2379-
Default: None, which will take the value from the
2380-
``errorbar.capsize`` :data:`rcParam<matplotlib.rcParams>`.
2377+
Default: None, which will take the value from
2378+
:rc:`errorbar.capsize`.
23812379
23822380
error_kw : dict, optional
23832381
Dictionary of kwargs to be passed to the `~.Axes.errorbar`
@@ -2973,9 +2971,8 @@ def errorbar(self, x, y, yerr=None, xerr=None,
29732971
the current style is used.
29742972
29752973
capsize : scalar, optional, default: None
2976-
The length of the error bar caps in points. If None, it will
2977-
take the value from ``errorbar.capsize``
2978-
:data:`rcParam<matplotlib.rcParams>`.
2974+
The length of the error bar caps in points. If None, it will take
2975+
the value from :rc:`errorbar.capsize`.
29792976
29802977
capthick : scalar, optional, default: None
29812978
An alias to the keyword argument *markeredgewidth* (a.k.a. *mew*).
@@ -5609,9 +5606,9 @@ def pcolor(self, *args, **kwargs):
56095606
``edgecolors="none"`` is used. This eliminates artificial lines
56105607
at patch boundaries, and works regardless of the value of alpha.
56115608
If ``edgecolors`` is not "none", then the default ``antialiaseds``
5612-
is taken from ``rcParams['patch.antialiased']``, which defaults to
5613-
True. Stroking the edges may be preferred if ``alpha`` is 1, but
5614-
will cause artifacts otherwise.
5609+
is taken from :rc:`patch.antialiased`, which defaults to True.
5610+
Stroking the edges may be preferred if ``alpha`` is 1, but will
5611+
cause artifacts otherwise.
56155612
56165613
**kwargs :
56175614

lib/matplotlib/backends/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def pylab_setup(name=None):
2828
----------
2929
name : str, optional
3030
The name of the backend to use. If `None`, falls back to
31-
``matplotlib.get_backend()`` (which return ``rcParams['backend']``)
31+
``matplotlib.get_backend()`` (which return :rc:`backend`).
3232
3333
Returns
3434
-------

lib/matplotlib/dates.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,12 @@ def _dt64_to_ordinalf(d):
296296
def _from_ordinalf(x, tz=None):
297297
"""
298298
Convert Gregorian float of the date, preserving hours, minutes,
299-
seconds and microseconds. Return value is a :class:`datetime`.
299+
seconds and microseconds. Return value is a `~.datetime`.
300300
301-
The input date `x` is a float in ordinal days at UTC, and the output will
302-
be the specified :class:`datetime` object corresponding to that time in
303-
timezone `tz`, or if `tz` is `None`, in the timezone specified in
304-
`rcParams['timezone']`.
301+
The input date *x* is a float in ordinal days at UTC, and the output will
302+
be the specified `~.datetime` object corresponding to that time in
303+
timezone *tz*, or if *tz* is ``None``, in the timezone specified in
304+
:rc:`timezone`.
305305
"""
306306
if tz is None:
307307
tz = _get_rc_timezone()

0 commit comments

Comments
 (0)