Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 928e58c

Browse filesBrowse files
committed
Error on bad input to hexbin extents
1 parent d3892d5 commit 928e58c
Copy full SHA for 928e58c

File tree

Expand file treeCollapse file tree

2 files changed

+16
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-0
lines changed

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
+4Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+12Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.