Skip to content

Commit

Permalink
Merge pull request matplotlib#28106 from clementgilli/main
Browse files Browse the repository at this point in the history
Fix: [Bug]: Setting norm by string doesn't work for hexbin matplotlib#28105
  • Loading branch information
tacaswell authored Apr 29, 2024
2 parents 4cbef2d + df94d8a commit ba7dbf3
Show file tree
Hide file tree
Showing 2 changed files with 14 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 @@ -5238,11 +5238,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 @@ -5258,6 +5253,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 @@ -978,6 +978,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

0 comments on commit ba7dbf3

Please sign in to comment.