Skip to content

Adding elinestyle property to errorbar #29879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5019e57
Adding elinestyle property to errorbar and test case
hasanrashid Apr 6, 2025
cf79005
whitespaces in testcase
hasanrashid Apr 6, 2025
dd2be27
Merge branch 'matplotlib:main' into enh-29681-hr
hasanrashid Apr 8, 2025
3f139f2
Update lib/matplotlib/axes/_axes.py
hasanrashid Apr 8, 2025
2705eab
Merge branch 'matplotlib:main' into enh-29681-hr
hasanrashid Apr 9, 2025
7c68dd0
Merge branch 'matplotlib:main' into enh-29681-hr
hasanrashid Apr 13, 2025
596bcde
Update set eb_line_style and fix formatting issues
hasanrashid Apr 13, 2025
73137f6
Remove extra line from test_axes
hasanrashid Apr 13, 2025
0059043
Break line to reduce width in text_axes.py
hasanrashid Apr 13, 2025
2bdf70b
Remove trailing whitespaces from axes and test_axes.py
hasanrashid Apr 13, 2025
e412775
Move elinestyle to the end of the list
hasanrashid Apr 13, 2025
a02930f
Shorten line length in axes.py
hasanrashid Apr 13, 2025
26a73b4
accessing the correct property 'linestyle' in eb_line_style
hasanrashid Apr 13, 2025
9d0dece
removing unused code
hasanrashid Apr 13, 2025
9bb00ab
Merge branch 'matplotlib:main' into enh-29681-hr
hasanrashid Apr 20, 2025
896678f
Update lib/matplotlib/axes/_axes.pyi
hasanrashid Apr 20, 2025
2e49747
pyplot.py unwanted changes reverted
hasanrashid Apr 26, 2025
44638f3
Adding extra blank lines to fix style errors, and removing unnecessar…
hasanrashid Apr 27, 2025
c503592
Merge branch 'matplotlib:main' into enh-29681-hr
hasanrashid Apr 27, 2025
0e36c50
Updating test_axes.py tp test for dashed lines instead of default
hasanrashid Apr 29, 2025
430ef24
Merge branch 'matplotlib:main' into enh-29681-hr
hasanrashid Apr 29, 2025
ff0370a
Style fix
timhoffm Apr 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3460,7 +3460,8 @@ def _errorevery_to_mask(x, errorevery):
def errorbar(self, x, y, yerr=None, xerr=None,
fmt='', ecolor=None, elinewidth=None, capsize=None,
barsabove=False, lolims=False, uplims=False,
xlolims=False, xuplims=False, errorevery=1, capthick=None,
xlolims=False, xuplims=False, errorevery=1,
capthick=None, elinestyle=None,
**kwargs):
"""
Plot y versus x as lines and/or markers with attached errorbars.
Expand Down Expand Up @@ -3508,6 +3509,12 @@ def errorbar(self, x, y, yerr=None, xerr=None,
The linewidth of the errorbar lines. If None, the linewidth of
the current style is used.

elinestyle : str or tuple, default: 'solid'
The linestyle of the errorbar lines.
Valid values for linestyles include {'-', '--', '-.',
':', '', (offset, on-off-seq)}. See `.Line2D.set_linestyle` for a
complete description.

capsize : float, default: :rc:`errorbar.capsize`
The length of the error bar caps in points.

Expand Down Expand Up @@ -3709,6 +3716,9 @@ def _upcast_err(err):
if key in kwargs:
eb_lines_style[key] = kwargs[key]

if elinestyle is not None:
eb_lines_style['linestyle'] = elinestyle

# Make the style dict for caps (the "hats").
eb_cap_style = {**base_style, 'linestyle': 'none'}
capsize = mpl._val_or_rc(capsize, "errorbar.capsize")
Expand Down Expand Up @@ -3819,7 +3829,6 @@ def apply_mask(arrays, mask):
for axis in caplines:
for l in caplines[axis]:
self.add_line(l)

Copy link
Member

Choose a reason for hiding this comment

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

This looks like an accidental unrelated change. Let's not include this

self._request_autoscale_view()
caplines = caplines['x'] + caplines['y']
errorbar_container = ErrorbarContainer(
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/axes/_axes.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ class Axes(_AxesBase):
*,
ecolor: ColorType | None = ...,
elinewidth: float | None = ...,
elinestyle: LineStyleType | None=...,
capsize: float | None = ...,
barsabove: bool = ...,
lolims: bool | ArrayLike = ...,
Expand Down
12 changes: 1 addition & 11 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3041,7 +3041,7 @@ def bar_label(
*,
fmt: str | Callable[[float], str] = "%g",
label_type: Literal["center", "edge"] = "edge",
padding: float | ArrayLike = 0,
padding: float = 0,
**kwargs,
) -> list[Annotation]:
return gca().bar_label(
Expand Down Expand Up @@ -4117,9 +4117,6 @@ def streamplot(
integration_direction="both",
broken_streamlines=True,
*,
integration_max_step_scale=1.0,
integration_max_error_scale=1.0,
num_arrows=1,
Copy link
Member

Choose a reason for hiding this comment

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

did boilerplate.py do these changes? This should not be modified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe so. I have not added anything to this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ran boilerplate.py in another branch without any of my changes. These changes appear as a result.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I've opened a separate issue on this. For this PR, please just revert the unwanted modifications.

Copy link
Member

@QuLogic QuLogic Apr 16, 2025

Choose a reason for hiding this comment

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

Did you run it outside an environment with the current version installed? The script imports matplotlib, so the only way it would be out of sync would be if it was using a different version.

It seems like that's the case because elinestyle hasn't been added anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was working on this branch using the conda environment mpl-dev in codespace

Copy link
Member

Choose a reason for hiding this comment

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

Are you definitely using Matplotlib installed from source?
https://matplotlib.org/devdocs/devel/development_setup.html#verify-the-installation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi. I will verify. I activated the condo envy and started working.

Copy link
Member

@rcomer rcomer Apr 16, 2025

Choose a reason for hiding this comment

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

Possibly you missed the install step then
https://matplotlib.org/devdocs/devel/development_setup.html#install-matplotlib-in-editable-mode

You will probably also need to set this before the install
#29852 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"You will probably also need to set this before the install
#29852 (comment)"

Thank you. I was getting an error in codespace while running pytest. This seems to have fixed it, but I don't recall seeing it in the documentation

data=None,
):
__ret = gca().streamplot(
Expand All @@ -4141,9 +4138,6 @@ def streamplot(
maxlength=maxlength,
integration_direction=integration_direction,
broken_streamlines=broken_streamlines,
integration_max_step_scale=integration_max_step_scale,
integration_max_error_scale=integration_max_error_scale,
num_arrows=num_arrows,
**({"data": data} if data is not None else {}),
)
sci(__ret.lines)
Expand Down Expand Up @@ -4291,8 +4285,6 @@ def violinplot(
| Callable[[GaussianKDE], float]
| None = None,
side: Literal["both", "low", "high"] = "both",
facecolor: Sequence[ColorType] | ColorType | None = None,
linecolor: Sequence[ColorType] | ColorType | None = None,
*,
data=None,
) -> dict[str, Collection]:
Expand All @@ -4309,8 +4301,6 @@ def violinplot(
points=points,
bw_method=bw_method,
side=side,
facecolor=facecolor,
linecolor=linecolor,
**({"data": data} if data is not None else {}),
)

Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4525,6 +4525,14 @@
def test_errorbar_linewidth_type(elinewidth):
plt.errorbar([1, 2, 3], [1, 2, 3], yerr=[1, 2, 3], elinewidth=elinewidth)

def test_errorbar_linestyle_type():
eb = plt.errorbar([1, 2, 3], [1, 2, 3],
yerr=[1, 2, 3], elinestyle='-')
assert eb[-1][0].get_linestyle() == '-'
eb = plt.errorbar([1, 2, 3], [1, 2, 3], xerr=[1, 2, 3],

Check warning on line 4532 in lib/matplotlib/tests/test_axes.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/tests/test_axes.py#L4532

Added line #L4532 was not covered by tests
yerr=[1, 2, 3], elinestyle=':')
assert eb[-1][0].get_linestyle() == ':'
assert eb[-1][1].get_linestyle() == ':'

Check warning on line 4535 in lib/matplotlib/tests/test_axes.py

View check run for this annotation

Codecov / codecov/patch

lib/matplotlib/tests/test_axes.py#L4534-L4535

Added lines #L4534 - L4535 were not covered by tests

@check_figures_equal()
def test_errorbar_nan(fig_test, fig_ref):
Expand Down
Loading