@@ -4326,9 +4326,23 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
43264326 offset_position = "data"
43274327 )
43284328
4329+ # Check for valid norm
4330+ if norm is not None and not isinstance (norm , mcolors .Normalize ):
4331+ msg = "'norm' must be an instance of 'mcolors.Normalize'"
4332+ raise ValueError (msg )
4333+
4334+ # Set normalizer if bins is 'log'
4335+ if bins == 'log' :
4336+ if norm is not None :
4337+ warnings .warn ("Only one of 'bins' and 'norm' arguments can be "
4338+ "supplied, ignoring bins={}" .format (bins ))
4339+ else :
4340+ norm = mcolors .LogNorm ()
4341+ bins = None
4342+
43294343 if isinstance (norm , mcolors .LogNorm ):
43304344 if (accum == 0 ).any ():
4331- # make sure we have not zeros
4345+ # make sure we have no zeros
43324346 accum += 1
43334347
43344348 # autoscale the norm with curren accum values if it hasn't
@@ -4337,20 +4351,14 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
43374351 if norm .vmin is None and norm .vmax is None :
43384352 norm .autoscale (accum )
43394353
4340- # Transform accum if needed
4341- if bins == 'log' :
4342- accum = np .log10 (accum + 1 )
4343- elif bins is not None :
4354+ if bins is not None :
43444355 if not iterable (bins ):
43454356 minimum , maximum = min (accum ), max (accum )
43464357 bins -= 1 # one less edge than bins
43474358 bins = minimum + (maximum - minimum ) * np .arange (bins ) / bins
43484359 bins = np .sort (bins )
43494360 accum = bins .searchsorted (accum )
43504361
4351- if norm is not None and not isinstance (norm , mcolors .Normalize ):
4352- raise ValueError (
4353- "'norm' must be an instance of 'mcolors.Normalize'" )
43544362 collection .set_array (accum )
43554363 collection .set_cmap (cmap )
43564364 collection .set_norm (norm )
0 commit comments