ENH: Adds `errorbar.capthick` and `errorbar.elinewidth` to mplstyle by Hannan7812 · Pull Request #31202 · matplotlib/matplotlib · GitHub
Skip to content

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

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

timhoffm merged 12 commits into
matplotlib: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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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

Copilot AI Feb 26, 2026

Copy link

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")

Copilot AI Feb 26, 2026

Copy link

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 <175728472+Copilot@users.noreply.github.com>

@timhoffm timhoffm left a comment

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.

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 <73029826+AlbertUnruh@users.noreply.github.com>
Incorporated suggestion to pass linting test W291

Co-authored-by: AlbertUnruh <73029826+AlbertUnruh@users.noreply.github.com>
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

timhoffm commented Mar 3, 2026

Copy link
Copy Markdown
Member

Thanks @Hannan7812 !

@QuLogic

QuLogic commented Mar 3, 2026

Copy link
Copy Markdown
Member

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

timhoffm commented Mar 3, 2026

Copy link
Copy Markdown
Member

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