Skip to content

Fixes incorrect error bar colors when NaN values are present #13825

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

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
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
14 changes: 14 additions & 0 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3211,6 +3211,20 @@ def errorbar(self, x, y, yerr=None, xerr=None,

if not np.iterable(y):
y = [y]
# The actual errorbar function works even if lengths of x and y
# dont matches with "ecolor" inorder to retain the same behavior
# the new change will only effect if lengths matches
if np.iterable(ecolor):
if len(ecolor) == len(x) and len(ecolor) == len(y):
# To get np.nan indices in both x and y lists
nan_indices = list(np.where(np.isnan(x))[
0]) + list(np.where(np.isnan(y))[0])
# To remove duplicates
nan_indices = list(set(nan_indices))
ecolor = np.array(ecolor)
# To delete colors corrresonding to np.nan in x and y
ecolor = np.delete(ecolor, nan_indices)
ecolor = list(ecolor)

if xerr is not None:
if not np.iterable(xerr):
Expand Down