Skip to content

Backport PR #23333: Fix errorbar handling of nan. #23344

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

Merged
Merged
Show file tree
Hide file tree
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
25 changes: 14 additions & 11 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,13 +1060,14 @@ def hlines(self, y, xmin, xmax, colors=None, linestyles='solid',
lines.update(kwargs)

if len(y) > 0:
minx = min(xmin.min(), xmax.min())
maxx = max(xmin.max(), xmax.max())
miny = y.min()
maxy = y.max()

# Extreme values of xmin/xmax/y. Using masked_verts here handles
# the case of y being a masked *object* array (as can be generated
# e.g. by errorbar()), which would make nanmin/nanmax stumble.
minx = np.nanmin(masked_verts[..., 0])
maxx = np.nanmax(masked_verts[..., 0])
miny = np.nanmin(masked_verts[..., 1])
maxy = np.nanmax(masked_verts[..., 1])
corners = (minx, miny), (maxx, maxy)

self.update_datalim(corners)
self._request_autoscale_view()

Expand Down Expand Up @@ -1139,11 +1140,13 @@ def vlines(self, x, ymin, ymax, colors=None, linestyles='solid',
lines.update(kwargs)

if len(x) > 0:
minx = x.min()
maxx = x.max()
miny = min(ymin.min(), ymax.min())
maxy = max(ymin.max(), ymax.max())

# Extreme values of x/ymin/ymax. Using masked_verts here handles
# the case of x being a masked *object* array (as can be generated
# e.g. by errorbar()), which would make nanmin/nanmax stumble.
minx = np.nanmin(masked_verts[..., 0])
maxx = np.nanmax(masked_verts[..., 0])
miny = np.nanmin(masked_verts[..., 1])
maxy = np.nanmax(masked_verts[..., 1])
corners = (minx, miny), (maxx, maxy)
self.update_datalim(corners)
self._request_autoscale_view()
Expand Down
14 changes: 14 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3633,6 +3633,20 @@ def test_errorbar_linewidth_type(elinewidth):
plt.errorbar([1, 2, 3], [1, 2, 3], yerr=[1, 2, 3], elinewidth=elinewidth)


@check_figures_equal(extensions=["png"])
def test_errorbar_nan(fig_test, fig_ref):
ax = fig_test.add_subplot()
xs = range(5)
ys = np.array([1, 2, np.nan, np.nan, 3])
es = np.array([4, 5, np.nan, np.nan, 6])
ax.errorbar(xs, ys, es)
ax = fig_ref.add_subplot()
ys = np.array([1, 2, np.nan, np.nan, 3])
es = np.array([4, 5, np.nan, np.nan, 6])
ax.errorbar([0, 1], [1, 2], [4, 5])
ax.errorbar([4], [3], [6], fmt="C0")


@image_comparison(['hist_stacked_stepfilled', 'hist_stacked_stepfilled'])
def test_hist_stacked_stepfilled():
# make some data
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy