8000 Fix hexbin raising ValueError on empty dataset · matplotlib/matplotlib@e864d94 · GitHub
[go: up one dir, main page]

Skip to content

Commit e864d94

Browse files
author
Umair Idris
committed
Fix hexbin raising ValueError on empty dataset
1 parent 30f9def commit e864d94

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3846,10 +3846,9 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
38463846
if extent is not None:
38473847
xmin, xmax, ymin, ymax = extent
38483848
else:
3849-
xmin = np.amin(x)
3850-
xmax = np.amax(x)
3851-
ymin = np.amin(y)
3852-
ymax = np.amax(y)
3849+
xmin, xmax = (np.amin(x), np.amax(x)) if x else (0, 1)
3850+
ymin, ymax = (np.amin(y), np.amax(y)) if y else (0, 1)
3851+
38533852
# to avoid issues with singular data, expand the min/max pairs
38543853
xmin, xmax = mtrans.nonsingular(xmin, xmax, expander=0.1)
38553854
ymin, ymax = mtrans.nonsingular(ymin, ymax, expander=0.1)
@@ -5606,8 +5605,6 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
56065605

56075606
# basic input validation
56085607
flat = np.ravel(x)
5609-
if len(flat) == 0:
5610-
raise ValueError("x must have at least one data point")
56115608

56125609
# Massage 'x' for processing.
56135610
# NOTE: Be sure any changes here is also done below to 'weights'

lib/matplotlib/tests/test_axes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ def test_hexbin_extent():
482482

483483
ax.hexbin(x, y, extent=[.1, .3, .6, .7])
484484

485+
def test_hexbin_empty():
486+
# From #3886: creating hexbin on empty dataset raises ValueError
487+
ax.hexbin([], [])
485488

486489
@cleanup
487490
def test_hexbin_pickable():

0 commit comments

Comments
 (0)
0