Skip to content

Commit 98f30b8

Browse files
author
Clement Gilli
committed
solve issue #28105
1 parent acfef85 commit 98f30b8

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/matplotlib/axes/_axes.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -5228,11 +5228,6 @@ def reduce_C_function(C: array) -> float
52285228
vmin = vmax = None
52295229
bins = None
52305230

5231-
# autoscale the norm with current accum values if it hasn't been set
5232-
if norm is not None:
5233-
if norm.vmin is None and norm.vmax is None:
5234-
norm.autoscale(accum)
5235-
52365231
if bins is not None:
52375232
if not np.iterable(bins):
52385233
minimum, maximum = min(accum), max(accum)
@@ -5248,6 +5243,11 @@ def reduce_C_function(C: array) -> float
52485243
collection._internal_update(kwargs)
52495244
collection._scale_norm(norm, vmin, vmax)
52505245

5246+
# autoscale the norm with current accum values if it hasn't been set
5247+
if norm is not None:
5248+
if collection.norm.vmin is None and collection.norm.vmax is None:
5249+
collection.norm.autoscale()
5250+
52515251
corners = ((xmin, ymin), (xmax, ymax))
52525252
self.update_datalim(corners)
52535253
self._request_autoscale_view(tight=True)

lib/matplotlib/tests/test_axes.py

+7
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,13 @@ def test_hexbin_bad_extents():
976976
with pytest.raises(ValueError, match="In extent, ymax must be greater than ymin"):
977977
ax.hexbin(x, y, extent=(0, 1, 1, 0))
978978

979+
def test_hexbin_string_norm():
980+
fig, ax = plt.subplots()
981+
hex = ax.hexbin(np.random.rand(10), np.random.rand(10), norm="log",vmin=2,vmax=5)
982+
assert isinstance(hex,matplotlib.collections.PolyCollection)
983+
assert isinstance(hex.norm,matplotlib.colors.LogNorm)
984+
assert hex.norm.vmin == 2
985+
assert hex.norm.vmax == 5
979986

980987
@image_comparison(['hexbin_empty.png'], remove_text=True)
981988
def test_hexbin_empty():

0 commit comments

Comments
 (0)