Skip to content

Commit

Permalink
solve issue matplotlib#28105
Browse files Browse the repository at this point in the history
  • Loading branch information
Clement Gilli committed Apr 19, 2024
1 parent acfef85 commit 98f30b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
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
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,13 @@ def test_hexbin_bad_extents():
with pytest.raises(ValueError, match="In extent, ymax must be greater than ymin"):
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():
Expand Down

0 comments on commit 98f30b8

Please sign in to comment.