Skip to content

Commit 928e58c

Browse files
committed
Error on bad input to hexbin extents
1 parent d3892d5 commit 928e58c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4999,6 +4999,10 @@ def reduce_C_function(C: array) -> float
49994999
ty = np.log10(ty)
50005000
if extent is not None:
50015001
xmin, xmax, ymin, ymax = extent
5002+
if xmin > xmax:
5003+
raise ValueError("In extent, xmax must be greater than xmin")
5004+
if ymin > ymax:
5005+
raise ValueError("In extent, ymax must be greater than ymin")
50025006
else:
50035007
xmin, xmax = (tx.min(), tx.max()) if len(x) else (0, 1)
50045008
ymin, ymax = (ty.min(), ty.max()) if len(y) else (0, 1)

lib/matplotlib/tests/test_axes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,18 @@ def test_hexbin_extent():
962962
ax.hexbin("x", "y", extent=[.1, .3, .6, .7], data=data)
963963

964964

965+
def test_hexbin_bad_extents():
966+
fig, ax = plt.subplots()
967+
data = (np.arange(2000) / 2000).reshape((2, 1000))
968+
x, y = data
969+
970+
with pytest.raises(ValueError, match="In extent, xmax must be greater than xmin"):
971+
ax.hexbin(x, y, extent=(1, 0, 0, 1))
972+
973+
with pytest.raises(ValueError, match="In extent, ymax must be greater than ymin"):
974+
ax.hexbin(x, y, extent=(0, 1, 1, 0))
975+
976+
965977
@image_comparison(['hexbin_empty.png'], remove_text=True)
966978
def test_hexbin_empty():
967979
# From #3886: creating hexbin from empty dataset raises ValueError

0 commit comments

Comments
 (0)
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