Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5228,11 +5228,6 @@ def reduce_C_function(C: array) -> float
vmin = vmax = None
bins = None

# 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)

if bins is not None:
if not np.iterable(bins):
minimum, maximum = min(accum), max(accum)
Expand All @@ -5248,6 +5243,11 @@ def reduce_C_function(C: array) -> float
collection._internal_update(kwargs)
collection._scale_norm(norm, vmin, vmax)

# autoscale the norm with current accum values if it hasn't been set
if norm is not None:
if collection.norm.vmin is None and collection.norm.vmax is None:
collection.norm.autoscale()

corners = ((xmin, ymin), (xmax, ymax))
self.update_datalim(corners)
self._request_autoscale_view(tight=True)
Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,15 @@ def test_hexbin_bad_extents():
ax.hexbin(x, y, extent=(0, 1, 1, 0))


def test_hexbin_string_norm():
fig, ax = plt.subplots()
hex = ax.hexbin(np.random.rand(10), np.random.rand(10), norm="log", vmin=2, vmax=5)
assert isinstance(hex, matplotlib.collections.PolyCollection)
assert isinstance(hex.norm, matplotlib.colors.LogNorm)
assert hex.norm.vmin == 2
assert hex.norm.vmax == 5


@image_comparison(['hexbin_empty.png'], remove_text=True)
def test_hexbin_empty():
# From #3886: creating hexbin from empty dataset raises ValueError
Expand Down