Skip to content

Commit 192e935

Browse files
hasanrashidtimhoffmQuLogic
authored
Add elinestyle property to errorbar (#29879)
* Adding elinestyle property to errorbar and test case * whitespaces in testcase * Update lib/matplotlib/axes/_axes.py Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> * Update set eb_line_style and fix formatting issues * Remove extra line from test_axes * Break line to reduce width in text_axes.py * Remove trailing whitespaces from axes and test_axes.py * Move elinestyle to the end of the list * Shorten line length in axes.py * accessing the correct property 'linestyle' in eb_line_style * removing unused code * Update lib/matplotlib/axes/_axes.pyi Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com> * pyplot.py unwanted changes reverted * Adding extra blank lines to fix style errors, and removing unnecessary asserts * Updating test_axes.py tp test for dashed lines instead of default * Style fix --------- Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
1 parent 033b666 commit 192e935

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

lib/matplotlib/axes/_axes.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -3463,7 +3463,8 @@ def _errorevery_to_mask(x, errorevery):
34633463
def errorbar(self, x, y, yerr=None, xerr=None,
34643464
fmt='', ecolor=None, elinewidth=None, capsize=None,
34653465
barsabove=False, lolims=False, uplims=False,
3466-
xlolims=False, xuplims=False, errorevery=1, capthick=None,
3466+
xlolims=False, xuplims=False, errorevery=1,
3467+
capthick=None, elinestyle=None,
34673468
**kwargs):
34683469
"""
34693470
Plot y versus x as lines and/or markers with attached errorbars.
@@ -3511,6 +3512,12 @@ def errorbar(self, x, y, yerr=None, xerr=None,
35113512
The linewidth of the errorbar lines. If None, the linewidth of
35123513
the current style is used.
35133514
3515+
elinestyle : str or tuple, default: 'solid'
3516+
The linestyle of the errorbar lines.
3517+
Valid values for linestyles include {'-', '--', '-.',
3518+
':', '', (offset, on-off-seq)}. See `.Line2D.set_linestyle` for a
3519+
complete description.
3520+
35143521
capsize : float, default: :rc:`errorbar.capsize`
35153522
The length of the error bar caps in points.
35163523
@@ -3712,6 +3719,9 @@ def _upcast_err(err):
37123719
if key in kwargs:
37133720
eb_lines_style[key] = kwargs[key]
37143721

3722+
if elinestyle is not None:
3723+
eb_lines_style['linestyle'] = elinestyle
3724+
37153725
# Make the style dict for caps (the "hats").
37163726
eb_cap_style = {**base_style, 'linestyle': 'none'}
37173727
capsize = mpl._val_or_rc(capsize, "errorbar.capsize")

lib/matplotlib/axes/_axes.pyi

+1
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ class Axes(_AxesBase):
315315
*,
316316
ecolor: ColorType | None = ...,
317317
elinewidth: float | None = ...,
318+
elinestyle: LineStyleType | None = ...,
318319
capsize: float | None = ...,
319320
barsabove: bool = ...,
320321
lolims: bool | ArrayLike = ...,

lib/matplotlib/pyplot.py

+2
Original file line numberDiff line numberDiff line change
@@ -3281,6 +3281,7 @@ def errorbar(
32813281
xuplims: bool | ArrayLike = False,
32823282
errorevery: int | tuple[int, int] = 1,
32833283
capthick: float | None = None,
3284+
elinestyle: LineStyleType | None = None,
32843285
*,
32853286
data=None,
32863287
**kwargs,
@@ -3301,6 +3302,7 @@ def errorbar(
33013302
xuplims=xuplims,
33023303
errorevery=errorevery,
33033304
capthick=capthick,
3305+
elinestyle=elinestyle,
33043306
**({"data": data} if data is not None else {}),
33053307
**kwargs,
33063308
)

lib/matplotlib/tests/test_axes.py

+8
Original file line numberDiff line numberDiff line change
@@ -4526,6 +4526,14 @@ def test_errorbar_linewidth_type(elinewidth):
45264526
plt.errorbar([1, 2, 3], [1, 2, 3], yerr=[1, 2, 3], elinewidth=elinewidth)
45274527

45284528

4529+
def test_errorbar_linestyle_type():
4530+
eb = plt.errorbar([1, 2, 3], [1, 2, 3],
4531+
yerr=[1, 2, 3], elinestyle='--')
4532+
errorlines = eb[-1][0]
4533+
errorlinestyle = errorlines.get_linestyle()
4534+
assert errorlinestyle == [(0, (6, 6))]
4535+
4536+
45294537
@check_figures_equal()
45304538
def test_errorbar_nan(fig_test, fig_ref):
45314539
ax = fig_test.add_subplot()

0 commit comments

Comments
 (0)