Skip to content

Commit ba7dbf3

Browse files
authored
Merge pull request #28106 from clementgilli/main
Fix: [Bug]: Setting norm by string doesn't work for hexbin #28105
2 parents 4cbef2d + df94d8a commit ba7dbf3

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5238,11 +5238,6 @@ def reduce_C_function(C: array) -> float
52385238
vmin = vmax = None
52395239
bins = None
52405240

5241-
# autoscale the norm with current accum values if it hasn't been set
5242-
if norm is not None:
5243-
if norm.vmin is None and norm.vmax is None:
5244-
norm.autoscale(accum)
5245-
52465241
if bins is not None:
52475242
if not np.iterable(bins):
52485243
minimum, maximum = min(accum), max(accum)
@@ -5258,6 +5253,11 @@ def reduce_C_function(C: array) -> float
52585253
collection._internal_update(kwargs)
52595254
collection._scale_norm(norm, vmin, vmax)
52605255

5256+
# autoscale the norm with current accum values if it hasn't been set
5257+
if norm is not None:
5258+
if collection.norm.vmin is None and collection.norm.vmax is None:
5259+
collection.norm.autoscale()
5260+
52615261
corners = ((xmin, ymin), (xmax, ymax))
52625262
self.update_datalim(corners)
52635263
self._request_autoscale_view(tight=True)

lib/matplotlib/tests/test_axes.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,15 @@ def test_hexbin_bad_extents():
978978
ax.hexbin(x, y, extent=(0, 1, 1, 0))
979979

980980

981+
def test_hexbin_string_norm():
982+
fig, ax = plt.subplots()
983+
hex = ax.hexbin(np.random.rand(10), np.random.rand(10), norm="log", vmin=2, vmax=5)
984+
assert isinstance(hex, matplotlib.collections.PolyCollection)
985+
assert isinstance(hex.norm, matplotlib.colors.LogNorm)
986+
assert hex.norm.vmin == 2
987+
assert hex.norm.vmax == 5
988+
989+
981990
@image_comparison(['hexbin_empty.png'], remove_text=True)
982991
def test_hexbin_empty():
983992
# From #3886: creating hexbin from empty dataset raises ValueError

0 commit comments

Comments
 (0)