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

Skip to content

Commit af904fc

Browse files
committed
FIX: ensure errorbar creates line collection even with empty data
closes #9699
1 parent 9527ba5 commit af904fc

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
@@ -3033,7 +3033,7 @@ def extract_err(err, data):
30333033
# select points without upper/lower limits in x and
30343034
# draw normal errorbars for these points
30353035
noxlims = ~(xlolims | xuplims)
3036-
if noxlims.any():
3036+
if noxlims.any() or len(noxlims) == 0:
30373037
yo, _ = xywhere(y, right, noxlims & everymask)
30383038
lo, ro = xywhere(left, right, noxlims & everymask)
30393039
barcols.append(self.hlines(yo, lo, ro, **eb_lines_style))
@@ -3082,7 +3082,7 @@ def extract_err(err, data):
30823082
# select points without upper/lower limits in y and
30833083
# draw normal errorbars for these points
30843084
noylims = ~(lolims | uplims)
3085-
if noylims.any():
3085+
if noylims.any() or len(noylims) == 0:
30863086
xo, _ = xywhere(x, lower, noylims & everymask)
30873087
lo, uo = xywhere(lower, upper, noylims & everymask)
30883088
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
@@ -5402,3 +5402,10 @@ def test_polar_gridlines():
54025402

54035403
assert ax.xaxis.majorTicks[0].gridline.get_alpha() == .2
54045404
assert ax.yaxis.majorTicks[0].gridline.get_alpha() == .2
5405+
5406+
5407+
def test_empty_errorbar_legend():
5408+
fig, ax = plt.subplots()
5409+
ax.errorbar([], [], xerr=[], label='empty y')
5410+
ax.errorbar([], [], yerr=[], label='empty x')
5411+
ax.legend()

0 commit comments

Comments
 (0)