From 928e58c4d8ca5ef18e2b51c0c492efaa2552039b Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 9 Jan 2024 13:19:22 +0000 Subject: [PATCH 1/2] Error on bad input to hexbin extents --- lib/matplotlib/axes/_axes.py | 4 ++++ lib/matplotlib/tests/test_axes.py | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 74243b71a152..ecb0e611af89 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -4999,6 +4999,10 @@ def reduce_C_function(C: array) -> float ty = np.log10(ty) if extent is not None: xmin, xmax, ymin, ymax = extent + if xmin > xmax: + raise ValueError("In extent, xmax must be greater than xmin") + if ymin > ymax: + raise ValueError("In extent, ymax must be greater than ymin") else: xmin, xmax = (tx.min(), tx.max()) if len(x) else (0, 1) ymin, ymax = (ty.min(), ty.max()) if len(y) else (0, 1) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index d8d7cb0144f1..d77b1662cf63 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -962,6 +962,18 @@ def test_hexbin_extent(): ax.hexbin("x", "y", extent=[.1, .3, .6, .7], data=data) +def test_hexbin_bad_extents(): + fig, ax = plt.subplots() + data = (np.arange(2000) / 2000).reshape((2, 1000)) + x, y = data + + with pytest.raises(ValueError, match="In extent, xmax must be greater than xmin"): + ax.hexbin(x, y, extent=(1, 0, 0, 1)) + + with pytest.raises(ValueError, match="In extent, ymax must be greater than ymin"): + ax.hexbin(x, y, extent=(0, 1, 1, 0)) + + @image_comparison(['hexbin_empty.png'], remove_text=True) def test_hexbin_empty(): # From #3886: creating hexbin from empty dataset raises ValueError From df3f93c71f3dd4062ddb8b1dc37d32ce0c6199b6 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Wed, 10 Jan 2024 10:27:50 +0000 Subject: [PATCH 2/2] Reduce size of test data Co-authored-by: Elliott Sales de Andrade --- lib/matplotlib/tests/test_axes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index d77b1662cf63..e3379b7ed78f 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -964,7 +964,7 @@ def test_hexbin_extent(): def test_hexbin_bad_extents(): fig, ax = plt.subplots() - data = (np.arange(2000) / 2000).reshape((2, 1000)) + data = (np.arange(20) / 20).reshape((2, 10)) x, y = data with pytest.raises(ValueError, match="In extent, xmax must be greater than xmin"): 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