@@ -244,6 +244,32 @@ def tick_values(self, vmin, vmax):
244244 return ticks [(ticks >= vmin ) & (ticks <= vmax )]
245245
246246
247+ class _ColorbarAutoMinorLocator (ticker .AutoMinorLocator ):
248+ """
249+ AutoMinorLocator for Colorbar
250+
251+ This locator is just a `.AutoMinorLocator` except the min and max are
252+ clipped by the norm's min and max (i.e. vmin/vmax from the
253+ image/pcolor/contour object). This is necessary so that the minorticks
254+ don't extrude into the "extend regions".
255+ """
256+
257+ def __init__ (self , colorbar , n = None ):
258+ """
259+ This ticker needs to know the *colorbar* so that it can access
260+ its *vmin* and *vmax*.
261+ """
262+ self ._colorbar = colorbar
263+ self .ndivs = n
264+ ticker .AutoMinorLocator .__init__ (self , n = None )
265+
266+ def __call__ (self ):
267+ vmin = self ._colorbar .norm .vmin
268+ vmax = self ._colorbar .norm .vmax
269+ ticks = ticker .AutoMinorLocator .__call__ (self )
270+ return ticks [(ticks >= vmin ) & (ticks <= vmax )]
271+
272+
247273class _ColorbarLogLocator (ticker .LogLocator ):
248274 """
249275 LogLocator for Colorbarbar
@@ -1164,6 +1190,33 @@ def remove(self):
11641190 # use_gridspec was True
11651191 ax .set_subplotspec (subplotspec )
11661192
1193+ def minorticks_on (self ):
1194+ """
1195+ Turns on the minor ticks on the colorbar without extruding
1196+ into the "extend regions".
1197+ """
1198+ ax = self .ax
1199+ long_axis = ax .yaxis if self .orientation == 'vertical' else ax .xaxis
1200+
1201+ if long_axis .get_scale () == 'log' :
1202+ warnings .warn ('minorticks_on() has no effect on a '
1203+ 'logarithmic colorbar axis' )
1204+ else :
1205+ long_axis .set_minor_locator (_ColorbarAutoMinorLocator (self ))
1206+
1207+ def minorticks_off (self ):
1208+ """
1209+ Turns off the minor ticks on the colorbar.
1210+ """
1211+ ax = self .ax
1212+ long_axis = ax .yaxis if self .orientation == 'vertical' else ax .xaxis
1213+
1214+ if long_axis .get_scale () == 'log' :
1215+ warnings .warn ('minorticks_off() has no effect on a '
1216+ 'logarithmic colorbar axis' )
1217+ else :
1218+ long_axis .set_minor_locator (ticker .NullLocator ())
1219+
11671220
11681221@docstring .Substitution (make_axes_kw_doc )
11691222def make_axes (parents , location = None , orientation = None , fraction = 0.15 ,
0 commit comments