Issue 1:
Bug summary

plt.errorbar don't give result when only nan data in the xerr or yerr. This is similar to issue #24127.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
plt.errorbar(x=[0], y=[0], xerr =[np.nan], yerr=[np.nan])
plt.show()

Actual outcome

StopIteration Traceback (most recent call last)

in

1 import numpy as np

2 import matplotlib.pyplot as plt

----> 3 plt.errorbar(x=[0], y=[0], xerr =[np.nan], yerr=[np.nan])

4 plt.show()

4 frames

/usr/local/lib/python3.9/dist-packages/matplotlib/pyplot.py in errorbar(x, y, yerr, xerr, fmt, ecolor, elinewidth, capsize, barsabove, lolims, uplims, xlolims, xuplims, errorevery, capthick, data, **kwargs)

2562 uplims=False, xlolims=False, xuplims=False, errorevery=1,

2563 capthick=None, *, data=None, **kwargs):

-> 2564 return gca().errorbar(

2565 x, y, yerr=yerr, xerr=xerr, fmt=fmt, ecolor=ecolor,

2566 elinewidth=elinewidth, capsize=capsize, barsabove=barsabove,

/usr/local/lib/python3.9/dist-packages/matplotlib/init.py in inner(ax, data, *args, **kwargs)

1440 def inner(ax, *args, data=None, **kwargs):

1441 if data is None:

-> 1442 return func(ax, *map(sanitize_sequence, args), **kwargs)

1443

1444 bound = new_sig.bind(ax, *args, **kwargs)

/usr/local/lib/python3.9/dist-packages/matplotlib/axes/_axes.py in errorbar(self, x, y, yerr, xerr, fmt, ecolor, elinewidth, capsize, barsabove, lolims, uplims, xlolims, xuplims, errorevery, capthick, **kwargs)

3530

3531 if xerr is not None and not isinstance(xerr, np.ndarray):

-> 3532 xerr = _upcast_err(xerr)

3533 if yerr is not None and not isinstance(yerr, np.ndarray):

3534 yerr = _upcast_err(yerr)

/usr/local/lib/python3.9/dist-packages/matplotlib/axes/_axes.py in _upcast_err(err)

3514 # location first on pandas objects so err[0] almost always

3515 # fails.

-> 3516 isinstance(cbook._safe_first_finite(err), np.ndarray)

3517 ):

3518 # Get the type of the first element

/usr/local/lib/python3.9/dist-packages/matplotlib/cbook/init.py in _safe_first_finite(obj, skip_nonfinite)

1713 "support generators as input")

1714 else:

-> 1715 return next(val for val in obj if safe_isfinite(val))

1716

1717

StopIteration:

Expected outcome

Plot nothing

Additional information

No response

Operating system

colab

Matplotlib Version

3.7.1

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

None

Issue 2:
Bug summary

The function ax.errorbar raises a StopIteration error when yerr contains only NaN values.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(1, 1)
ax.errorbar([0], [0], [np.nan])

Actual outcome

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "~/.local/share/virtualenvs/pipeline/lib/python3.9/site-packages/matplotlib/__init__.py", line 1423, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File "~.local/share/virtualenvs/pipeline/lib/python3.9/site-packages/matplotlib/axes/_axes.py", line 3488, in errorbar
yerr = _upcast_err(yerr)
File "~/.local/share/virtualenvs/pipeline/lib/python3.9/site-packages/matplotlib/axes/_axes.py", line 3470, in _upcast_err
isinstance(cbook._safe_first_finite(err), np.ndarray)
File "~/.local/share/virtualenvs/pipeline/lib/python3.9/site-packages/matplotlib/cbook/__init__.py", line 1749, in _safe_first_finite
return next(val for val in obj if safe_isfinite(val))
StopIteration

Expected outcome

No crash, similar to the case where only some values are NaN.

Additional information

This happens because _upcast_err unconditionally looks for a first finite element in xerr and yerr.

Operating system

Debian

Matplotlib Version

3.6.2

Matplotlib Backend

TkAgg

Python version

3.9.2

Jupyter version

No response

Installation

pip