ENH: Adds errorbar.capthick and errorbar.elinewidth to mplstyle#31202
ENH: Adds errorbar.capthick and errorbar.elinewidth to mplstyle#31202timhoffm merged 12 commits intomatplotlib:mainfrom
errorbar.capthick and errorbar.elinewidth to mplstyle#31202Conversation
Merges with an updated upstream into the current branch for fixing the issue
|
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. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
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 <[email protected]>
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 <[email protected]>
Incorporated suggestion to pass linting test W291 Co-authored-by: AlbertUnruh <[email protected]>
2c6b1ce to
58596fb
Compare
|
Thanks @Hannan7812 ! |
|
Note, there was no second review here... I'm wondering why the rcParam is |
|
Given the combination of
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 |
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:
