@@ -107,9 +107,10 @@ def __init__(self, fig,
107
107
share_all = False ,
108
108
share_x = True ,
109
109
share_y = True ,
110
- #aspect=True,
111
110
label_mode = "L" ,
112
111
axes_class = None ,
112
+ * ,
113
+ aspect = False ,
113
114
):
114
115
"""
115
116
Parameters
@@ -136,6 +137,7 @@ def __init__(self, fig,
136
137
- "all": all axes are labelled.
137
138
138
139
axes_class : subclass of `matplotlib.axes.Axes`, default: None
140
+ aspect : bool, default: False
139
141
"""
140
142
self ._nrows , self ._ncols = nrows_ncols
141
143
@@ -155,7 +157,7 @@ def __init__(self, fig,
155
157
if axes_class is None :
156
158
axes_class = self ._defaultAxesClass
157
159
158
- kw = dict (horizontal = [], vertical = [], aspect = False )
160
+ kw = dict (horizontal = [], vertical = [], aspect = aspect )
159
161
if isinstance (rect , (str , Number , SubplotSpec )):
160
162
self ._divider = SubplotDivider (fig , rect , ** kw )
161
163
elif len (rect ) == 3 :
@@ -182,7 +184,7 @@ def __init__(self, fig,
182
184
self .axes_row = axes_array .tolist ()
183
185
self .axes_llc = self .axes_column [0 ][- 1 ]
184
186
185
- self ._update_locators ()
187
+ self ._init_locators ()
186
188
187
189
if add_all :
188
190
for ax in self .axes_all :
@@ -195,7 +197,7 @@ def _init_axes_pad(self, axes_pad):
195
197
self ._horiz_pad_size = Size .Fixed (axes_pad [0 ])
196
198
self ._vert_pad_size = Size .Fixed (axes_pad [1 ])
197
199
198
- def _update_locators (self ):
200
+ def _init_locators (self ):
199
201
200
202
h = []
201
203
h_ax_pos = []
@@ -401,73 +403,20 @@ def __init__(self, fig,
401
403
to associated *cbar_axes*.
402
404
axes_class : subclass of `matplotlib.axes.Axes`, default: None
403
405
"""
404
- self ._nrows , self ._ncols = nrows_ncols
405
-
406
- if ngrids is None :
407
- ngrids = self ._nrows * self ._ncols
408
- else :
409
- if not 0 < ngrids <= self ._nrows * self ._ncols :
410
- raise Exception
411
-
412
- self .ngrids = ngrids
413
-
414
- self ._init_axes_pad (axes_pad )
415
-
416
406
self ._colorbar_mode = cbar_mode
417
407
self ._colorbar_location = cbar_location
418
- if cbar_pad is None :
419
- # horizontal or vertical arrangement?
420
- if cbar_location in ("left" , "right" ):
421
- self ._colorbar_pad = self ._horiz_pad_size .fixed_size
422
- else :
423
- self ._colorbar_pad = self ._vert_pad_size .fixed_size
424
- else :
425
- self ._colorbar_pad = cbar_pad
426
-
408
+ self ._colorbar_pad = cbar_pad
427
409
self ._colorbar_size = cbar_size
410
+ # The colorbar axes are created in _init_locators().
428
411
429
- cbook ._check_in_list (["column" , "row" ], direction = direction )
430
- self ._direction = direction
431
-
432
- if axes_class is None :
433
- axes_class = self ._defaultAxesClass
434
-
435
- kw = dict (horizontal = [], vertical = [], aspect = aspect )
436
- if isinstance (rect , (str , Number , SubplotSpec )):
437
- self ._divider = SubplotDivider (fig , rect , ** kw )
438
- elif len (rect ) == 3 :
439
- self ._divider = SubplotDivider (fig , * rect , ** kw )
440
- elif len (rect ) == 4 :
441
- self ._divider = Divider (fig , rect , ** kw )
442
- else :
443
- raise Exception ("" )
444
-
445
- rect = self ._divider .get_position ()
446
-
447
- axes_array = np .full ((self ._nrows , self ._ncols ), None , dtype = object )
448
- for i in range (self .ngrids ):
449
- col , row = self ._get_col_row (i )
450
- if share_all :
451
- sharex = sharey = axes_array [0 , 0 ]
452
- else :
453
- sharex = axes_array [0 , col ]
454
- sharey = axes_array [row , 0 ]
455
- axes_array [row , col ] = axes_class (
456
- fig , rect , sharex = sharex , sharey = sharey )
457
- self .axes_all = axes_array .ravel ().tolist ()
458
- self .axes_column = axes_array .T .tolist ()
459
- self .axes_row = axes_array .tolist ()
460
- self .axes_llc = self .axes_column [0 ][- 1 ]
461
-
462
- self .cbar_axes = [
463
- self ._defaultCbarAxesClass (fig , rect ,
464
- orientation = self ._colorbar_location )
465
- for _ in range (self .ngrids )]
466
-
467
- self ._update_locators ()
412
+ super ().__init__ (
413
+ fig , rect , nrows_ncols , ngrids ,
414
+ direction = direction , axes_pad = axes_pad , add_all = add_all ,
415
+ share_all = share_all , share_x = True , share_y = True , aspect = aspect ,
416
+ label_mode = label_mode , axes_class = axes_class )
468
417
469
418
if add_all :
470
- for ax in self .axes_all + self . cbar_axes :
419
+ for ax in self .cbar_axes :
471
420
fig .add_axes (ax )
472
421
473
422
if cbar_set_cax :
@@ -485,9 +434,20 @@ def __init__(self, fig,
485
434
for ax , cax in zip (self .axes_all , self .cbar_axes ):
486
435
ax .cax = cax
487
436
488
- self .set_label_mode (label_mode )
437
+ def _init_locators (self ):
438
+ # Slightly abusing this method to inject colorbar creation into init.
489
439
490
- def _update_locators (self ):
440
+ if self ._colorbar_pad is None :
441
+ # horizontal or vertical arrangement?
442
+ if self ._colorbar_location in ("left" , "right" ):
443
+ self ._colorbar_pad = self ._horiz_pad_size .fixed_size
444
+ else :
445
+ self ._colorbar_pad = self ._vert_pad_size .fixed_size
446
+ self .cbar_axes = [
447
+ self ._defaultCbarAxesClass (
448
+ self .axes_all [0 ].figure , self ._divider .get_position (),
449
+ orientation = self ._colorbar_location )
450
+ for _ in range (self .ngrids )]
491
451
492
452
cb_mode = self ._colorbar_mode
493
453
cb_location = self ._colorbar_location
0 commit comments