diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index be4a1b12cc39..1a88a1cd7300 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -4154,6 +4154,7 @@ def _upcast_err(err): # Make the style dict for the line collections (the bars). eb_lines_style = {**base_style, 'color': ecolor} + elinewidth = mpl._val_or_rc(elinewidth, "errorbar.elinewidth") if elinewidth is not None: eb_lines_style['linewidth'] = elinewidth @@ -4170,6 +4171,8 @@ def _upcast_err(err): # Make the style dict for caps (the "hats"). eb_cap_style = {**base_style, 'linestyle': 'none'} capsize = mpl._val_or_rc(capsize, "errorbar.capsize") + capthick = mpl._val_or_rc(capthick, "errorbar.capthick") + if capsize > 0: eb_cap_style['markersize'] = 2. * capsize if capthick is not None: diff --git a/lib/matplotlib/mpl-data/matplotlibrc b/lib/matplotlib/mpl-data/matplotlibrc index 17705fe60347..777de295fae6 100644 --- a/lib/matplotlib/mpl-data/matplotlibrc +++ b/lib/matplotlib/mpl-data/matplotlibrc @@ -662,6 +662,8 @@ ## * ERRORBAR PLOTS * ## *************************************************************************** #errorbar.capsize: 0 # length of end cap on error bars in pixels +#errorbar.capthick: None # thickness of end cap on error bars in points +#errorbar.elinewidth: None # line width of error bar lines in points ## *************************************************************************** diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index ce6633868091..33cc3447b70b 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -1114,6 +1114,8 @@ def _convert_validator_spec(key, conv): # errorbar props "errorbar.capsize": validate_float, + "errorbar.capthick": validate_float_or_None, + "errorbar.elinewidth": validate_float_or_None, # axis props # alignment of x/y axis title @@ -2918,6 +2920,17 @@ class _Subsection: validator=validate_float, description="length of end cap on error bars in pixels" ), + _Param( + "errorbar.capthick", + default=None, + validator=validate_float_or_None, + description="thickness of end cap on error bars in points."), + _Param( + "errorbar.elinewidth", + default=None, + validator=validate_float_or_None, + description="line width of the error bar lines in points." + ), _Section("Histogram plots"), _Param( "hist.bins", diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index a58b6f88e5ea..74d48a89d0c0 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -10155,3 +10155,22 @@ def test_animated_artists_not_drawn_by_default(): mocked_im_draw.assert_not_called() mocked_ln_draw.assert_not_called() + + +def test_errorbar_uses_rcparams(): + with mpl.rc_context({ + "errorbar.capsize": 5.0, + "errorbar.capthick": 2.5, + "errorbar.elinewidth": 1.75, + }): + fig, ax = plt.subplots() + eb = ax.errorbar([0, 1, 2], [1, 2, 3], yerr=[0.1, 0.2, 0.3], fmt="none") + + data_line, caplines, barlinecols = eb.lines + assert data_line is None + assert caplines + + assert_allclose([cap.get_markersize() for cap in caplines], 10.0) + assert_allclose([cap.get_markeredgewidth() for cap in caplines], 2.5) + for barcol in barlinecols: + assert_allclose(barcol.get_linewidths(), 1.75) diff --git a/lib/matplotlib/typing.py b/lib/matplotlib/typing.py index d2e12c6e08d9..6a1dc3e4a1d3 100644 --- a/lib/matplotlib/typing.py +++ b/lib/matplotlib/typing.py @@ -281,6 +281,8 @@ "date.interval_multiples", "docstring.hardcopy", "errorbar.capsize", + "errorbar.capthick", + "errorbar.elinewidth", "figure.autolayout", "figure.constrained_layout.h_pad", "figure.constrained_layout.hspace",