@@ -218,6 +218,7 @@ def _set_ticks_on_axis_warn(*args, **kw):
218218 # set_xticks set_yticks by _patch_ax
219219 warnings .warn ("Use the colorbar set_ticks() method instead." )
220220
221+
221222class ColorbarAutoLocator (ticker .MaxNLocator ):
222223 """ AutoLocator for Colorbar
223224 """
@@ -228,12 +229,12 @@ def __init__(self, colorbar, *args, **kwargs):
228229 steps = [1 , 2 , 2.5 , 5 , 10 ]
229230 ticker .MaxNLocator .__init__ (self , nbins = nbins , steps = steps )
230231
231-
232232 def tick_values (self , vmin , vmax ):
233233 vmin = max (vmin , self ._colorbar .norm .vmin )
234234 vmax = min (vmax , self ._colorbar .norm .vmax )
235235 return ticker .MaxNLocator .tick_values (self , vmin , vmax )
236236
237+
237238class ColorbarBase (cm .ScalarMappable ):
238239 '''
239240 Draw a colorbar in an existing axes.
@@ -394,7 +395,6 @@ def config_axis(self):
394395
395396 self ._set_label ()
396397
397-
398398 def _get_ticker_locator_formatter (self ):
399399 locator = self .locator
400400 formatter = self .formatter
@@ -426,6 +426,16 @@ def _get_ticker_locator_formatter(self):
426426 locator = ticker .FixedLocator (b , nbins = 10 )
427427 return locator , formatter
428428
429+ def _use_adjustable (self ):
430+ """
E765
tr>431+ Return if we should use an adjustable tick locator or a fixed
432+ one. (check is used twice so factored out here...)
433+ """
434+ return (self .boundaries is None
435+ and self .values is None
436+ and not isinstance (self .norm , colors .BoundaryNorm ))
437+
438+
429439 def update_ticks (self ):
430440 """
431441 Force the update of the ticks and ticklabels. This must be
@@ -435,7 +445,8 @@ def update_ticks(self):
435445 # get the locator and formatter. Defaults to
436446 # self.locator if not None..
437447 locator , formatter = self ._get_ticker_locator_formatter ()
438- if self .boundaries is None and self .values is None :
448+
449+ if self ._use_adjustable ():
439450 _log .debug ('Using adjustable locator on colorbar' )
440451 if self .orientation == 'vertical' :
441452 ax .yaxis .set_major_locator (locator )
@@ -898,7 +909,7 @@ def _mesh(self):
898909 # scale this up for Auto tick location. Otherwise we
899910 # want to keep normalized between 0 and 1 and use manual tick
900911 # locations.
901- if self .boundaries is None and self . values is None :
912+ if self ._use_adjustable () :
902913 dy = self .vmax - self .vmin
903914 y = y * dy + self .vmin
904915 x = x * dy
0 commit comments