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

Skip to content

Commit ade25fb

Browse files
authored
Merge pull request #9709 from tacaswell/fix_empty_errorbar_legend
FIX: ensure errorbar creates line collection even with empty data
2 parents 764a541 + af904fc commit ade25fb

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2969,7 +2969,7 @@ def extract_err(err, data):
29692969
# select points without upper/lower limits in x and
29702970
# draw normal errorbars for these points
29712971
noxlims = ~(xlolims | xuplims)
2972-
if noxlims.any():
2972+
if noxlims.any() or len(noxlims) == 0:
29732973
yo, _ = xywhere(y, right, noxlims & everymask)
29742974
lo, ro = xywhere(left, right, noxlims & everymask)
29752975
barcols.append(self.hlines(yo, lo, ro, **eb_lines_style))
@@ -3018,7 +3018,7 @@ def extract_err(err, data):
30183018
# select points without upper/lower limits in y and
30193019
# draw normal errorbars for these points
30203020
noylims = ~(lolims | uplims)
3021-
if noylims.any():
3021+
if noylims.any() or len(noylims) == 0:
30223022
xo, _ = xywhere(x, lower, noylims & everymask)
30233023
lo, uo = xywhere(lower, upper, noylims & everymask)
30243024
barcols.append(self.vlines(xo, lo, uo, **eb_lines_style))

lib/matplotlib/tests/test_axes.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5412,3 +5412,10 @@ def test_polar_gridlines():
54125412

54135413
assert ax.xaxis.majorTicks[0].gridline.get_alpha() == .2
54145414
assert ax.yaxis.majorTicks[0].gridline.get_alpha() == .2
5415+
5416+
5417+
def test_empty_errorbar_legend():
5418+
fig, ax = plt.subplots()
5419+
ax.errorbar([], [], xerr=[], label='empty y')
5420+
ax.errorbar([], [], yerr=[], label='empty x')
5421+
ax.legend()

0 commit comments

Comments
 (0)