1818is a thin wrapper over :meth:`~matplotlib.figure.Figure.colorbar`.
1919
2020'''
21-
21+ import copy
2222import logging
2323
2424import numpy as np
@@ -489,6 +489,7 @@ def draw_all(self):
489489 # units:
490490 X , Y = self ._mesh ()
491491 C = self ._values [:, np .newaxis ]
492+ # decide minor/major axis
492493 self .config_axis ()
493494 self ._config_axes (X , Y )
494495 if self .filled :
@@ -565,10 +566,11 @@ def _use_auto_colorbar_locator(self):
565566 Return if we should use an adjustable tick locator or a fixed
566567 one. (check is used twice so factored out here...)
567568 """
568- return (self .boundaries is None
569- and self .values is None
570- and ((type (self .norm ) == colors .Normalize )
571- or (type (self .norm ) == colors .LogNorm )))
569+ contouring = ((self .boundaries is not None ) and
570+ (self .spacing == 'uniform' ))
571+ return (((type (self .norm ) == colors .Normalize )
572+ or (type (self .norm ) == colors .LogNorm ))
573+ and not contouring )
572574
573575 def _reset_locator_formatter_scale (self ):
574576 """
@@ -578,13 +580,11 @@ def _reset_locator_formatter_scale(self):
578580 """
579581 self .locator = None
580582 self .formatter = None
581- if (isinstance (self .norm , colors .LogNorm )
582- and self ._use_auto_colorbar_locator ()):
583+ if (isinstance (self .norm , colors .LogNorm )):
583584 # *both* axes are made log so that determining the
584585 # mid point is easier.
585586 self .ax .set_xscale ('log' )
586587 self .ax .set_yscale ('log' )
587-
588588 self .minorticks_on ()
589589 else :
590590 self .ax .set_xscale ('linear' )
@@ -1066,26 +1066,35 @@ def _mesh(self):
10661066 These are suitable for a vertical colorbar; swapping and
10671067 transposition for a horizontal colorbar are done outside
10681068 this function.
1069- '''
1070- # if boundaries and values are None, then we can go ahead and
1071- # scale this up for Auto tick location. Otherwise we
1072- # want to keep normalized between 0 and 1 and use manual tick
1073- # locations.
10741069
1070+ These are scaled between vmin and vmax
1071+ '''
1072+ # copy the norm and change the vmin and vmax to the vmin and
1073+ # vmax of the colorbar, not the norm. This allows the situation
1074+ # where the colormap has a narrower range than the colorbar, to
1075+ # accomodate extra contours:
1076+ norm = copy .copy (self .norm )
1077+ norm .vmin = self .vmin
1078+ norm .vmax = self .vmax
10751079 x = np .array ([0.0 , 1.0 ])
10761080 if self .spacing == 'uniform' :
10771081 y = self ._uniform_y (self ._central_N ())
10781082 else :
10791083 y = self ._proportional_y ()
1080- if self ._use_auto_colorbar_locator ():
1081- y = self .norm .inverse (y )
1082- x = self .norm .inverse (x )
1084+ xmid = np .array ([0.5 ])
1085+ try :
1086+ y = norm .inverse (y )
1087+ x = norm .inverse (x )
1088+ xmid = norm .inverse (xmid )
1089+ except ValueError :
1090+ # occurs for norms that don't have an inverse, in
1091+ # which case manually scale:
1092+ dv = self .vmax - self .vmin
1093+ x = x * dv + self .vmin
1094+ y = y * dv + self .vmin
1095+ xmid = xmid * dv + self .vmin
10831096 self ._y = y
10841097 X , Y = np .meshgrid (x , y )
1085- if self ._use_auto_colorbar_locator ():
1086- xmid = self .norm .inverse (0.5 )
1087- else :
1088- xmid = 0.5
10891098 if self ._extend_lower () and not self .extendrect :
10901099 X [0 , :] = xmid
10911100 if self ._extend_upper () and not self .extendrect :
0 commit comments