Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e3d6dfc

Browse files
Hannan7812CopilottimhoffmAlbertUnruh
authored
ENH: Adds errorbar.capthick and errorbar.elinewidth to mplstyle (#31202)
* Added 2 new rcparams: errorbar.capthick and errorbar.elinewidth * Modified _axes.py to properly render the rcparams * Fixed minor formatting to pass linter tests * Update lib/matplotlib/mpl-data/matplotlibrc Fixed documentation formatting Co-authored-by: Copilot <[email protected]> * Adressed reviewer comments and added a test * DOC: Add sections to rcParams documentation * Apply suggestion from @timhoffm * Update lib/matplotlib/tests/test_axes.py Incorporated suggestion to satisfy linting rule Co-authored-by: AlbertUnruh <[email protected]> * Update lib/matplotlib/tests/test_axes.py Incorporated suggestion to pass linting test W291 Co-authored-by: AlbertUnruh <[email protected]> * Moved capthick to line 4174 --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: Tim Hoffmann <[email protected]> Co-authored-by: AlbertUnruh <[email protected]>
1 parent 2bd2c45 commit e3d6dfc

5 files changed

Lines changed: 39 additions & 0 deletions

File tree

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4154,6 +4154,7 @@ def _upcast_err(err):
41544154

41554155
# Make the style dict for the line collections (the bars).
41564156
eb_lines_style = {**base_style, 'color': ecolor}
4157+
elinewidth = mpl._val_or_rc(elinewidth, "errorbar.elinewidth")
41574158

41584159
if elinewidth is not None:
41594160
eb_lines_style['linewidth'] = elinewidth
@@ -4170,6 +4171,8 @@ def _upcast_err(err):
41704171
# Make the style dict for caps (the "hats").
41714172
eb_cap_style = {**base_style, 'linestyle': 'none'}
41724173
capsize = mpl._val_or_rc(capsize, "errorbar.capsize")
4174+
capthick = mpl._val_or_rc(capthick, "errorbar.capthick")
4175+
41734176
if capsize > 0:
41744177
eb_cap_style['markersize'] = 2. * capsize
41754178
if capthick is not None:

lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,8 @@
662662
## * ERRORBAR PLOTS *
663663
## ***************************************************************************
664664
#errorbar.capsize: 0 # length of end cap on error bars in pixels
665+
#errorbar.capthick: None # thickness of end cap on error bars in points
666+
#errorbar.elinewidth: None # line width of error bar lines in points
665667

666668

667669
## ***************************************************************************

lib/matplotlib/rcsetup.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,8 @@ def _convert_validator_spec(key, conv):
11141114

11151115
# errorbar props
11161116
"errorbar.capsize": validate_float,
1117+
"errorbar.capthick": validate_float_or_None,
1118+
"errorbar.elinewidth": validate_float_or_None,
11171119

11181120
# axis props
11191121
# alignment of x/y axis title
@@ -2918,6 +2920,17 @@ class _Subsection:
29182920
validator=validate_float,
29192921
description="length of end cap on error bars in pixels"
29202922
),
2923+
_Param(
2924+
"errorbar.capthick",
2925+
default=None,
2926+
validator=validate_float_or_None,
2927+
description="thickness of end cap on error bars in points."),
2928+
_Param(
2929+
"errorbar.elinewidth",
2930+
default=None,
2931+
validator=validate_float_or_None,
2932+
description="line width of the error bar lines in points."
2933+
),
29212934
_Section("Histogram plots"),
29222935
_Param(
29232936
"hist.bins",

lib/matplotlib/tests/test_axes.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10155,3 +10155,22 @@ def test_animated_artists_not_drawn_by_default():
1015510155

1015610156
mocked_im_draw.assert_not_called()
1015710157
mocked_ln_draw.assert_not_called()
10158+
10159+
10160+
def test_errorbar_uses_rcparams():
10161+
with mpl.rc_context({
10162+
"errorbar.capsize": 5.0,
10163+
"errorbar.capthick": 2.5,
10164+
"errorbar.elinewidth": 1.75,
10165+
}):
10166+
fig, ax = plt.subplots()
10167+
eb = ax.errorbar([0, 1, 2], [1, 2, 3], yerr=[0.1, 0.2, 0.3], fmt="none")
10168+
10169+
data_line, caplines, barlinecols = eb.lines
10170+
assert data_line is None
10171+
assert caplines
10172+
10173+
assert_allclose([cap.get_markersize() for cap in caplines], 10.0)
10174+
assert_allclose([cap.get_markeredgewidth() for cap in caplines], 2.5)
10175+
for barcol in barlinecols:
10176+
assert_allclose(barcol.get_linewidths(), 1.75)

lib/matplotlib/typing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@
281281
"date.interval_multiples",
282282
"docstring.hardcopy",
283283
"errorbar.capsize",
284+
"errorbar.capthick",
285+
"errorbar.elinewidth",
284286
"figure.autolayout",
285287
"figure.constrained_layout.h_pad",
286288
"figure.constrained_layout.hspace",

0 commit comments

Comments
 (0)