From c6339567de1cbe1a75e97020ef93388364b0261b Mon Sep 17 00:00:00 2001 From: erykoff Date: Thu, 22 Sep 2022 21:39:13 -0700 Subject: [PATCH] Backport PR #23944: FIX: ValueError when hexbin is run with empty arrays and log scaling. --- lib/matplotlib/axes/_axes.py | 4 +++- lib/matplotlib/tests/test_axes.py | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 6327dde85276..c578765bfa1c 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -4927,7 +4927,9 @@ def reduce_C_function(C: array) -> float # autoscale the norm with current accum values if it hasn't been set if norm is not None: if norm.vmin is None and norm.vmax is None: - norm.autoscale(accum) + norm.autoscale_None(accum) + norm.vmin = np.ma.masked if norm.vmin is None else norm.vmin + norm.vmax = np.ma.masked if norm.vmax is None else norm.vmax if bins is not None: if not np.iterable(bins): diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 628f9542aa42..b35b3feacf18 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -901,6 +901,14 @@ def test_hexbin_empty(): ax.hexbin([], []) +@image_comparison(['hexbin_empty.png'], remove_text=True) +def test_hexbin_log_empty(): + # From #23922: creating hexbin with log scaling from empty + # dataset raises ValueError + ax = plt.gca() + ax.hexbin([], [], bins='log') + + def test_hexbin_pickable(): # From #1973: Test that picking a hexbin collection works fig, ax = plt.subplots()