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

Skip to content

ENH: Adds errorbar.capthick and errorbar.elinewidth to mplstyle#31202

Merged
timhoffm merged 12 commits intomatplotlib:mainfrom
Hannan7812:fix-issue-31194
Mar 3, 2026
Merged

ENH: Adds errorbar.capthick and errorbar.elinewidth to mplstyle#31202
timhoffm merged 12 commits intomatplotlib:mainfrom
Hannan7812:fix-issue-31194

Conversation

@Hannan7812
Copy link
Copy Markdown
Contributor

PR summary

PR checklist

  • "closes #0000" is in the body of the PR description to link the related issue
  • new and changed code is tested (Note that only test/test_axes.py was run because that was the only file changed)
  • [N/A] Plotting related features are demonstrated in an example
  • [N/A] New Features and API Changes are noted with a directive and release note
  • Documentation complies with general and docstring guidelines

Additional Notes

import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np

# Configure via rcParams (simulating stylesheet behavior)
plt.rcParams.update({
    "errorbar.capsize": 10,
    "errorbar.capthick": 10,
    "errorbar.elinewidth": 10,
})

x = np.arange(5)
y = x
yerr = 0.5

print(mpl.rcParams["errorbar.capthick"])
print(mpl.rcParams["errorbar.elinewidth"])

fig, ax = plt.subplots()
ax.errorbar(x, y, yerr=yerr)

plt.show()

Output:
Figure_1

Copilot AI review requested due to automatic review settings February 26, 2026 06:16
@github-actions
Copy link
Copy Markdown

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join us on gitter for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide.
Please let us know if (and how) you use AI, it will help us give you better feedback on your PR.

We strive to be a welcoming and open project. Please follow our Code of Conduct.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.capthick and errorbar.elinewidth as rcParams (validation, defaults, typing support).
  • Add the new keys to the default matplotlibrc template.
  • Update Axes.errorbar to source capthick / elinewidth from 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.

Comment thread lib/matplotlib/rcsetup.py
Comment thread lib/matplotlib/rcsetup.py
Comment thread lib/matplotlib/mpl-data/matplotlibrc Outdated
Comment thread lib/matplotlib/axes/_axes.py Outdated
Comment on lines +4172 to +4180
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
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread lib/matplotlib/axes/_axes.py Outdated
Comment on lines +4173 to +4174
capthick = mpl._val_or_rc(capthick, "errorbar.capthick")
elinewidth = mpl._val_or_rc(elinewidth, "errorbar.elinewidth")
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Fixed documentation formatting

Co-authored-by: Copilot <[email protected]>
Copy link
Copy Markdown
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lib/matplotlib/axes/_axes.py Outdated
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")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This must be moved before l.4158

Comment thread lib/matplotlib/axes/_axes.py Outdated
Comment on lines +4179 to +4180
if eb_lines_style is not None:
eb_lines_style['linewidth'] = elinewidth
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't touch eb_lines_style again here. It should be built consistently in l.4155ff

@Hannan7812
Copy link
Copy Markdown
Contributor Author

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.

Comment thread lib/matplotlib/tests/test_axes.py
Comment thread lib/matplotlib/tests/test_axes.py Outdated
Hannan7812 and others added 2 commits February 27, 2026 09:18
Incorporated suggestion to satisfy linting rule

Co-authored-by: AlbertUnruh <[email protected]>
Incorporated suggestion to pass linting test W291

Co-authored-by: AlbertUnruh <[email protected]>
Comment thread lib/matplotlib/axes/_axes.py Outdated
@github-actions github-actions Bot added the Documentation: devdocs files in doc/devel label Feb 27, 2026
Comment thread doc/devel/contribute.rst Outdated
@github-actions github-actions Bot removed the Documentation: devdocs files in doc/devel label Feb 27, 2026
@timhoffm timhoffm added this to the v3.11.0 milestone Mar 3, 2026
@timhoffm timhoffm merged commit e3d6dfc into matplotlib:main Mar 3, 2026
38 of 40 checks passed
@timhoffm
Copy link
Copy Markdown
Member

timhoffm commented Mar 3, 2026

Thanks @Hannan7812 !

@QuLogic
Copy link
Copy Markdown
Member

QuLogic commented Mar 3, 2026

Note, there was no second review here...

I'm wondering why the rcParam is errorbar.elinewidth, instead of errorbar.linewidth. The e prefix is in the method arguments to separate the errorbar arguments from the regular line arguments, but the rcParam is already in the errorbar group, so it seems extraneous.

@timhoffm
Copy link
Copy Markdown
Member

timhoffm commented Mar 3, 2026

Given the combination of

  • this being a relative straight forward change
  • low review capacity (we leave a lot of PRs unreviewed or even waiting for a second review)
  • A review by Albert (My bad, I thought it was the Ablert doing all the numeric fixes and counted this as a half review - there are too many Alberts around now)

I empowered myself to move this forward after waiting for 3 days whether somebody wanted to comment.

It was a mistake due to mixing up the Alberts. I shouldn't have done it.

But overall we do have a review problem. In particular, we should talk about ways to get a second review if a first approval is there. PRs with one review have a decent quality and it's typically comparably low effort to do the second review. We shouldn't leave them on the table because. (1) They increase the amout of work in progess. (2) They are rather low haning fruits for improvment. (3) Not following up discourages contibutors.


On errorbar.elinewidth vs. errorbar.linewidth: One can argument both ways. I'm inclinded to go with the structural mapping rcParams["<method>.<parameter>"]. We have a number of parameters that follow this pattern.
It's also not much effort to spend the additional e and it makes it very obvious that one can it is for the elinewidth parameter. Whereas errorbar.linewidth would leave some room for misunderstanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENH]: add errorbar.capthick and errorbar.elinewidth to mplstyle

5 participants