@@ -19,6 +19,11 @@ def _tick_only(ax, bottom_on, left_on):
1919
2020
2121class  CbarAxesBase :
22+     def  __init__ (self , * args , orientation , ** kwargs ):
23+         self .orientation  =  orientation 
24+         self ._default_label_on  =  True 
25+         self ._locator  =  None   # deprecated. 
26+         super ().__init__ (* args , ** kwargs )
2227
2328    @cbook ._rename_parameter ("3.2" , "locator" , "ticks" ) 
2429    def  colorbar (self , mappable , * , ticks = None , ** kwargs ):
@@ -38,21 +43,30 @@ def colorbar(self, mappable, *, ticks=None, **kwargs):
3843            if  ticks  is  None :
3944                ticks  =  ticker .MaxNLocator (5 )  # For backcompat. 
4045            from  .colorbar  import  Colorbar 
46+             cb  =  Colorbar (
47+                 self , mappable , orientation = orientation , ticks = ticks , ** kwargs )
48+             self ._cbid  =  mappable .callbacksSM .connect (
49+                 'changed' , cb .update_normal )
50+             mappable .colorbar  =  cb 
51+             self ._locator  =  cb .cbar_axis .get_major_locator ()
4152        else :
42-             from   matplotlib .colorbar   import   Colorbar 
43-         cb   =   Colorbar ( 
44-             self ,  mappable ,  orientation = orientation ,  ticks = ticks ,  ** kwargs ) 
45-         self ._config_axes () 
53+             cb   =   mpl .colorbar . colorbar_factory ( 
54+                  self ,  mappable ,  orientation = orientation ,  ticks = ticks ,  ** kwargs ) 
55+             self . _cbid   =   mappable . colorbar_cid    # deprecated. 
56+              self ._locator   =   cb . locator    # deprecated. 
4657
47-         self .cbid   =   mappable . callbacksSM . connect ( 'changed' ,  cb . update_normal )
48-         mappable . colorbar   =  cb 
58+         self ._config_axes ( )
59+         return  cb 
4960
50-          if   mpl . rcParams [ "mpl_toolkits.legacy_colorbar" ]: 
51-              self . locator   =   cb . cbar_axis . get_major_locator () 
52-          else :
53-              self .locator   =   cb . locator 
61+     @ cbook . deprecated ( "3.3" ,  alternative = "mappable.colorbar_cid" ) 
62+     @ property 
63+     def   cbid ( self ) :
64+         return   self ._cbid 
5465
55-         return  cb 
66+     @cbook .deprecated ("3.3" , alternative = ".colorbar().locator" ) 
67+     @property  
68+     def  locator (self ):
69+         return  self ._locator 
5670
5771    def  _config_axes (self ):
5872        """Make an axes patch and outline.""" 
@@ -67,19 +81,15 @@ def toggle_label(self, b):
6781        axis  =  self .axis [self .orientation ]
6882        axis .toggle (ticklabels = b , label = b )
6983
70- 
71- class  CbarAxes (CbarAxesBase , Axes ):
72-     def  __init__ (self , * args , orientation , ** kwargs ):
73-         self .orientation  =  orientation 
74-         self ._default_label_on  =  True 
75-         self .locator  =  None 
76-         super ().__init__ (* args , ** kwargs )
77- 
7884    def  cla (self ):
7985        super ().cla ()
8086        self ._config_axes ()
8187
8288
89+ class  CbarAxes (CbarAxesBase , Axes ):
90+     pass 
91+ 
92+ 
8393class  Grid :
8494    """ 
8595    A grid of Axes. 
0 commit comments