@@ -1451,7 +1451,33 @@ class _Param:
14511451 description : str = None
14521452
14531453
1454- _params = [
1454+ @dataclass
1455+ class _Section :
1456+ title : str
1457+ description : str = None
1458+
1459+
1460+ @dataclass
1461+ class _Subsection :
1462+ title : str
1463+ description : str = None
1464+
1465+
1466+ # Definition of all rcParams. This is currently only used to generate the documentation.
1467+ #
1468+ # Actual runtime values do still come from the historic sources:
1469+ # - available parameters and defaults: lib/matplotlib/mpl-data/matplotlibrc
1470+ # - validators: _validators, see above
1471+ #
1472+ # The structure and format of this definition is not fixed and may change in the future.
1473+ # It's a work-in-progress state towards a consistent and more structured definition of
1474+ # rcParams that can be used both for documentation and runtime. The goal is to
1475+ # eventually eliminate the old sources of defaults and validators and have this be the
1476+ # single source of truth.
1477+ #
1478+ # In the transition phase, consistency is ensured via tests.
1479+ _DEFINITION = [
1480+ _Section ("Backends" ),
14551481 _Param (
14561482 "webagg.port" ,
14571483 default = 8988 ,
@@ -1508,6 +1534,11 @@ class _Param:
15081534 validator = validate_string ,
15091535 description = "a pytz timezone string, e.g., US/Central or Europe/Paris"
15101536 ),
1537+ _Section (
1538+ "Lines" ,
1539+ description = "Default properties for line objects, such as those returned by "
1540+ "plot()."
1541+ ),
15111542 _Param (
15121543 "lines.linewidth" ,
15131544 default = 1.5 ,
@@ -1628,6 +1659,7 @@ class _Param:
16281659 "solely to allow old test images to remain unchanged. Set to False "
16291660 "to obtain the previous behavior."
16301661 ),
1662+ _Section ("Patches" ),
16311663 _Param (
16321664 "patch.linewidth" ,
16331665 default = 1.0 ,
@@ -1662,8 +1694,10 @@ class _Param:
16621694 validator = validate_bool ,
16631695 description = "render patches in antialiased (no jaggies)"
16641696 ),
1697+ _Section ("Hatches" ),
16651698 _Param ("hatch.color" , "edge" , _validate_color_or_edge ),
16661699 _Param ("hatch.linewidth" , 1.0 , validate_float ),
1700+ _Section ("Boxplot" ),
16671701 _Param ("boxplot.notch" , False , validate_bool ),
16681702 _Param ("boxplot.vertical" , True , validate_bool ),
16691703 _Param ("boxplot.whiskers" , 1.5 , validate_whiskers ),
@@ -1701,6 +1735,13 @@ class _Param:
17011735 _Param ("boxplot.meanprops.markersize" , 6.0 , validate_float ),
17021736 _Param ("boxplot.meanprops.linestyle" , "--" , _validate_linestyle ),
17031737 _Param ("boxplot.meanprops.linewidth" , 1.0 , validate_float ),
1738+ _Section (
1739+ "Font" ,
1740+ description = "The font properties used by `.Text` "
1741+ "See https://matplotlib.org/stable/api/font_manager_api.html for "
1742+ "more information on font properties. The 6 font properties used "
1743+ "for font matching are given below with their default values."
1744+ ),
17041745 _Param ("font.family" , ["sans-serif" ], validate_stringlist ),
17051746 _Param ("font.style" , "normal" , validate_string ),
17061747 _Param ("font.variant" , "normal" , validate_string ),
@@ -1756,6 +1797,7 @@ class _Param:
17561797 "appended to all font selections. This ensures that there will "
17571798 "always be a glyph displayed."
17581799 ),
1800+ _Section ("Text properties" ),
17591801 _Param (
17601802 "text.color" ,
17611803 default = "black" ,
@@ -1809,6 +1851,7 @@ class _Param:
18091851 description = "Use mathtext if there is an even number of unescaped dollar signs."
18101852
18111853 ),
1854+ _Section ("Mathtext and LaTeX" ),
18121855 _Param (
18131856 "text.usetex" ,
18141857 default = False ,
@@ -1867,6 +1910,7 @@ class _Param:
18671910 'names, including the special name "regular" for the same font '
18681911 'used in regular text.' ,
18691912 ),
1913+ _Section ("Axes" ),
18701914 _Param (
18711915 "axes.facecolor" ,
18721916 default = "white" ,
@@ -2078,12 +2122,14 @@ class _Param:
20782122 '"round_numbers", after application of margins, axis limits are '
20792123 'further expanded to the nearest "round" number.' ,
20802124 ),
2125+ _Subsection ("Polar Axes" ),
20812126 _Param (
20822127 "polaraxes.grid" ,
20832128 default = True ,
20842129 validator = validate_bool ,
20852130 description = "display grid on polar axes"
20862131 ),
2132+ _Subsection ("3D Axes" ),
20872133 _Param (
20882134 "axes3d.grid" ,
20892135 default = True ,
@@ -2144,6 +2190,7 @@ class _Param:
21442190 description = "trackball border width, in units of the Axes bbox (only for "
21452191 "'sphere' and 'arcball' style)"
21462192 ),
2193+ _Section ("Axis" ),
21472194 _Param (
21482195 "xaxis.labellocation" ,
21492196 default = "center" ,
@@ -2156,6 +2203,14 @@ class _Param:
21562203 validator = ["bottom" , "center" , "top" ],
21572204 description = "alignment of the yaxis label: {bottom, top, center}"
21582205 ),
2206+ _Section (
2207+ "Dates" ,
2208+ description = "Default properties for date tick labels. These are used by the "
2209+ "`.AutoDateFormatter` when the appropriate time unit is detected."
2210+ "See "
2211+ "https://matplotlib.org/stable/api/dates_api.html#date-formatters "
2212+ "for more information."
2213+ ),
21592214 _Param ("date.autoformatter.year" , "%Y" , validate_string ),
21602215 _Param ("date.autoformatter.month" , "%Y-%m" , validate_string ),
21612216 _Param ("date.autoformatter.day" , "%Y-%m-%d" , validate_string ),
@@ -2181,6 +2236,7 @@ class _Param:
21812236 validator = validate_bool ,
21822237 description = "For auto converter whether to use interval_multiples"
21832238 ),
2239+ _Section ("Ticks" ),
21842240 _Param (
21852241 "xtick.top" ,
21862242 default = False ,
@@ -2431,6 +2487,7 @@ class _Param:
24312487 ["center" , "top" , "bottom" , "baseline" , "center_baseline" ],
24322488 description = "alignment of yticks"
24332489 ),
2490+ _Section ("Grid" ),
24342491 _Param (
24352492 "grid.color" ,
24362493 default = "#b0b0b0" ,
@@ -2503,6 +2560,7 @@ class _Param:
25032560 validator = validate_float_or_None ,
25042561 description = "If None defaults to grid.alpha"
25052562 ),
2563+ _Section ("Legend" ),
25062564 _Param (
25072565 "legend.loc" ,
25082566 default = "best" ,
@@ -2627,6 +2685,7 @@ class _Param:
26272685 default = 2.0 ,
26282686 validator = validate_float , description = "column separation"
26292687 ),
2688+ _Section ("Figure" ),
26302689 _Param (
26312690 "figure.titlesize" ,
26322691 default = "large" ,
@@ -2778,6 +2837,7 @@ class _Param:
27782837 "figure.subplot.wspace) as constrained_layout already takes "
27792838 "surrounding texts (titles, labels, # ticklabels) into account."
27802839 ),
2840+ _Section ("Images" ),
27812841 _Param (
27822842 "image.aspect" ,
27832843 default = "equal" ,
@@ -2826,6 +2886,7 @@ class _Param:
28262886 "single composite image before saving a figure as a vector "
28272887 "graphics file, such as a PDF."
28282888 ),
2889+ _Section ("Contour plots" ),
28292890 _Param (
28302891 "contour.negative_linestyle" ,
28312892 default = "dashed" ,
@@ -2850,18 +2911,21 @@ class _Param:
28502911 validator = ["mpl2005" , "mpl2014" , "serial" , "threaded" ],
28512912 description = "{mpl2005, mpl2014, serial, threaded}"
28522913 ),
2914+ _Section ("Errorbar plots" ),
28532915 _Param (
28542916 "errorbar.capsize" ,
28552917 default = 0.0 ,
28562918 validator = validate_float ,
28572919 description = "length of end cap on error bars in pixels"
28582920 ),
2921+ _Section ("Histogram plots" ),
28592922 _Param (
28602923 "hist.bins" ,
28612924 default = 10 ,
28622925 validator = validate_hist_bins ,
28632926 description = "The default number of histogram bins or 'auto'."
28642927 ),
2928+ _Section ("Scatter plots" ),
28652929 _Param (
28662930 "scatter.marker" ,
28672931 default = "o" ,
@@ -2874,6 +2938,7 @@ class _Param:
28742938 validator = validate_string ,
28752939 description = "The default edge colors for scatter plots."
28762940 ),
2941+ _Section ("AGG rendering" ),
28772942 _Param (
28782943 "agg.path.chunksize" ,
28792944 default = 0 ,
@@ -2884,6 +2949,7 @@ class _Param:
28842949 "cause minor artifacts, though. A value of 20000 is probably a "
28852950 "good starting point."
28862951 ),
2952+ _Section ("Paths" ),
28872953 _Param (
28882954 "path.simplify" ,
28892955 default = True ,
@@ -2923,6 +2989,7 @@ class _Param:
29232989 default = [],
29242990 validator = validate_anylist
29252991 ),
2992+ _Section ("Saving figures" ),
29262993 _Param (
29272994 "savefig.dpi" ,
29282995 default = "figure" ,
@@ -2981,19 +3048,22 @@ class _Param:
29813048 validator = ["landscape" , "portrait" ],
29823049 description = "orientation of saved figure, for PostScript output only"
29833050 ),
3051+ _Subsection ("Mac OSX backend parameters" ),
29843052 _Param (
29853053 "macosx.window_mode" ,
29863054 default = "system" ,
29873055 validator = ["system" , "tab" , "window" ],
29883056 description = "How to open new figures (system, tab, window) system uses "
29893057 "the MacOS system preferences"
29903058 ),
3059+ _Subsection ("Tk backend parameters" ),
29913060 _Param (
29923061 "tk.window_focus" ,
29933062 default = False ,
29943063 validator = validate_bool ,
29953064 description = "Maintain shell focus for TkAgg"
29963065 ),
3066+ _Subsection ("PS backend parameters" ),
29973067 _Param (
29983068 "ps.papersize" ,
29993069 default = "letter" ,
@@ -3029,6 +3099,7 @@ class _Param:
30293099 validator = validate_fonttype ,
30303100 description = "Output Type 3 (Type3) or Type 42 (TrueType)"
30313101 ),
3102+ _Subsection ("PDF backend parameters" ),
30323103 _Param (
30333104 "pdf.compression" ,
30343105 default = 6 ,
@@ -3051,6 +3122,7 @@ class _Param:
30513122 default = False ,
30523123 validator = validate_bool
30533124 ),
3125+ _Subsection ("SVG backend parameters" ),
30543126 _Param (
30553127 "svg.image_inline" ,
30563128 default = True ,
@@ -3080,6 +3152,7 @@ class _Param:
30803152 description = "If not None, use this string as the value for the `id` attribute "
30813153 "in the top <svg> tag"
30823154 ),
3155+ _Subsection ("PGF parameters" ),
30833156 _Param (
30843157 "pgf.rcfonts" ,
30853158 default = True ,
@@ -3096,12 +3169,18 @@ class _Param:
30963169 default = "xelatex" ,
30973170 validator = ["xelatex" , "lualatex" , "pdflatex" ]
30983171 ),
3172+ _Subsection ("Docstring parameters" ),
30993173 _Param (
31003174 "docstring.hardcopy" ,
31013175 default = False ,
31023176 validator = validate_bool ,
31033177 description = "set this when you want to generate hardcopy docstring"
31043178 ),
3179+ _Section (
3180+ "Interactive keymaps" ,
3181+ description = "Default key mappings for interactive navigation. See "
3182+ ":ref:`key-event-handling`."
3183+ ),
31053184 _Param (
31063185 "keymap.fullscreen" ,
31073186 default = ["f" , "ctrl+f" ],
@@ -3188,6 +3267,7 @@ class _Param:
31883267 validator = validate_stringlist ,
31893268 description = "copy figure to clipboard"
31903269 ),
3270+ _Section ("Animation" ),
31913271 _Param (
31923272 "animation.html" ,
31933273 default = "none" ,
@@ -3261,3 +3341,7 @@ class _Param:
32613341 ),
32623342 _Param ("backend" , None , validate_backend ),
32633343]
3344+
3345+
3346+ def _params_list ():
3347+ return [elem for elem in _DEFINITION if isinstance (elem , _Param )]
0 commit comments