ENH: Adds errorbar.capthick and errorbar.elinewidth to mplstyle - #31202
Conversation
Merges with an updated upstream into the current branch for fixing the issue
There was a problem hiding this comment.
Pull request overview
This PR adds two new rcParams (errorbar.capthick and errorbar.elinewidth) so that cap thickness and errorbar line width can be configured via Matplotlib stylesheets (requested in #31194).
Changes:
- Register
errorbar.capthickanderrorbar.elinewidthas rcParams (validation, defaults, typing support). - Add the new keys to the default
matplotlibrctemplate. - Update
Axes.errorbarto sourcecapthick/elinewidthfrom rcParams when not explicitly provided.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| lib/matplotlib/typing.py | Adds the new rcParam keys to typing key lists. |
| lib/matplotlib/rcsetup.py | Defines validators and _Param metadata for the new rcParams. |
| lib/matplotlib/mpl-data/matplotlibrc | Adds commented defaults for the new rcParams in the template rc file. |
| lib/matplotlib/axes/_axes.py | Attempts to apply rcParam-backed defaults for capthick and elinewidth in Axes.errorbar. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| capsize = mpl._val_or_rc(capsize, "errorbar.capsize") | ||
| capthick = mpl._val_or_rc(capthick, "errorbar.capthick") | ||
| elinewidth = mpl._val_or_rc(elinewidth, "errorbar.elinewidth") | ||
| if capsize > 0: | ||
| eb_cap_style['markersize'] = 2. * capsize | ||
| if capthick is not None: | ||
| eb_cap_style['markeredgewidth'] = capthick | ||
| if eb_lines_style is not None: | ||
| eb_lines_style['linewidth'] = elinewidth |
There was a problem hiding this comment.
elinewidth is already handled earlier when building eb_lines_style; the new _val_or_rc block later unconditionally overwrites eb_lines_style['linewidth'] (even when the resolved rcParam is None). This can (a) clobber an explicitly provided linewidth kwarg and (b) set linewidth=None in the collection style, which may break downstream setters. Resolve elinewidth (including rc fallback) once, apply it only when non-None, and preserve the existing precedence where explicit elinewidth/linewidth overrides the rcParam default.
| capthick = mpl._val_or_rc(capthick, "errorbar.capthick") | ||
| elinewidth = mpl._val_or_rc(elinewidth, "errorbar.elinewidth") |
There was a problem hiding this comment.
New behavior (rcParams-backed defaults for capthick/elinewidth) is introduced here but there are no tests exercising rcParams['errorbar.capthick'] / rcParams['errorbar.elinewidth'] or their precedence vs explicit elinewidth/linewidth kwargs. Please add a test (likely in lib/matplotlib/tests/test_axes.py near existing errorbar tests) that sets these rcParams and asserts the resulting cap markeredgewidth and errorbar LineCollection linewidth.
Fixed documentation formatting Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
timhoffm
left a comment
There was a problem hiding this comment.
Please add tests to show that the rcParams are correctly used.
Note: I don't know why the AI review was triggered. Did you do this? You may or may not look at what it said. Sometimes it's useful, sometimes it isn't. For me as a maintainer, it's too much noise and I don't review AI, so I haven't looked at it.
| eb_cap_style = {**base_style, 'linestyle': 'none'} | ||
| capsize = mpl._val_or_rc(capsize, "errorbar.capsize") | ||
| capthick = mpl._val_or_rc(capthick, "errorbar.capthick") | ||
| elinewidth = mpl._val_or_rc(elinewidth, "errorbar.elinewidth") |
There was a problem hiding this comment.
This must be moved before l.4158
| if eb_lines_style is not None: | ||
| eb_lines_style['linewidth'] = elinewidth |
There was a problem hiding this comment.
Don't touch eb_lines_style again here. It should be built consistently in l.4155ff
|
I've added a test which checks that rcParams are correctly used. I've also made the suggested changes to the other comments. Let me know if I overlooked anything @timhoffm. PS, My apologies, I forgot to turn off automatic copilot reviews from my settings. |
Incorporated suggestion to satisfy linting rule Co-authored-by: AlbertUnruh <73029826+AlbertUnruh@users.noreply.github.com>
Incorporated suggestion to pass linting test W291 Co-authored-by: AlbertUnruh <73029826+AlbertUnruh@users.noreply.github.com>
2c6b1ce to
58596fb
Compare
|
Thanks @Hannan7812 ! |
|
Note, there was no second review here... I'm wondering why the rcParam is |

PR summary
As requested in [ENH]: add
errorbar.capthickanderrorbar.elinewidthto mplstyle #31194, this change introduces two new parameters configurable via stylesheets.It is an enhancement requested in the above mentioned issue.
It allows the user to set errorbar.capthick and errorbar.elinewidth once in the stylesheet without having to set them again and again. Closes [ENH]: add
errorbar.capthickanderrorbar.elinewidthto mplstyle #31194PR checklist
test/test_axes.pywas run because that was the only file changed)Additional Notes
Output:
