Skip to content

Commit 0636b9e

Browse files
authored
FIX: ValueError when hexbin is run with empty arrays and log scaling. (matplotlib#23944)
* Add test for empty hexbin with log scaling. * Use guarded autoscale_None for use when vmin/vmax are None. * Add additional check when auto vmin/vmax are None.
1 parent 33303ba commit 0636b9e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4943,7 +4943,9 @@ def reduce_C_function(C: array) -> float
49434943
# autoscale the norm with current accum values if it hasn't been set
49444944
if norm is not None:
49454945
if norm.vmin is None and norm.vmax is None:
4946-
norm.autoscale(accum)
4946+
norm.autoscale_None(accum)
4947+
norm.vmin = np.ma.masked if norm.vmin is None else norm.vmin
4948+
norm.vmax = np.ma.masked if norm.vmax is None else norm.vmax
49474949

49484950
if bins is not None:
49494951
if not np.iterable(bins):

lib/matplotlib/tests/test_axes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,14 @@ def test_hexbin_empty():
901901
ax.hexbin([], [])
902902

903903

904+
@image_comparison(['hexbin_empty.png'], remove_text=True)
905+
def test_hexbin_log_empty():
906+
# From #23922: creating hexbin with log scaling from empty
907+
# dataset raises ValueError
908+
ax = plt.gca()
909+
ax.hexbin([], [], bins='log')
910+
911+
904912
def test_hexbin_pickable():
905913
# From #1973: Test that picking a hexbin collection works
906914
fig, ax = plt.subplots()

0 commit comments

Comments
 (0)