14
14
import matplotlib .lines as mlines
15
15
import matplotlib .ticker as ticker
16
16
17
- from matplotlib .gridspec import SubplotSpec , GridSpec
17
+ from matplotlib .gridspec import SubplotSpec
18
18
19
19
from .axes_divider import Size , SubplotDivider , LocatableAxes , Divider
20
20
21
21
22
+ def _extend_axes_pad (value ):
23
+ # Check whether a list/tuple/array or scalar has been passed
24
+ ret = value
25
+ if not hasattr (ret , "__getitem__" ):
26
+ ret = (value , value )
27
+ return ret
28
+
22
29
def _tick_only (ax , bottom_on , left_on ):
23
30
bottom_off = not bottom_on
24
31
left_off = not left_on
@@ -200,6 +207,8 @@ def __init__(self, fig,
200
207
================ ======== =========================================
201
208
direction "row" [ "row" | "column" ]
202
209
axes_pad 0.02 float| pad between axes given in inches
210
+ or tuple-like of floats,
211
+ (horizontal padding, vertical padding)
203
212
add_all True [ True | False ]
204
213
share_all False [ True | False ]
205
214
share_x True [ True | False ]
@@ -238,8 +247,8 @@ def __init__(self, fig,
238
247
axes_class , axes_class_args = axes_class
239
248
240
249
self .axes_all = []
241
- self .axes_column = [[] for i in range (self ._ncols )]
242
- self .axes_row = [[] for i in range (self ._nrows )]
250
+ self .axes_column = [[] for _ in range (self ._ncols )]
251
+ self .axes_row = [[] for _ in range (self ._nrows )]
243
252
244
253
h = []
245
254
v = []
@@ -261,8 +270,8 @@ def __init__(self, fig,
261
270
rect = self ._divider .get_position ()
262
271
263
272
# reference axes
264
- self ._column_refax = [None for i in range (self ._ncols )]
265
- self ._row_refax = [None for i in range (self ._nrows )]
273
+ self ._column_refax = [None for _ in range (self ._ncols )]
274
+ self ._row_refax = [None for _ in range (self ._nrows )]
266
275
self ._refax = None
267
276
268
277
for i in range (self .ngrids ):
@@ -310,19 +319,19 @@ def __init__(self, fig,
310
319
self .set_label_mode (label_mode )
311
320
312
321
def _init_axes_pad (self , axes_pad ):
322
+ axes_pad = _extend_axes_pad (axes_pad )
313
323
self ._axes_pad = axes_pad
314
324
315
- self ._horiz_pad_size = Size .Fixed (axes_pad )
316
- self ._vert_pad_size = Size .Fixed (axes_pad )
325
+ self ._horiz_pad_size = Size .Fixed (axes_pad [ 0 ] )
326
+ self ._vert_pad_size = Size .Fixed (axes_pad [ 1 ] )
317
327
318
328
def _update_locators (self ):
319
329
320
330
h = []
321
331
322
332
h_ax_pos = []
323
- h_cb_pos = []
324
333
325
- for ax in self ._column_refax :
334
+ for _ in self ._column_refax :
326
335
#if h: h.append(Size.Fixed(self._axes_pad))
327
336
if h :
328
337
h .append (self ._horiz_pad_size )
@@ -335,8 +344,7 @@ def _update_locators(self):
335
344
v = []
336
345
337
346
v_ax_pos = []
338
- v_cb_pos = []
339
- for ax in self ._row_refax [::- 1 ]:
347
+ for _ in self ._row_refax [::- 1 ]:
340
348
#if v: v.append(Size.Fixed(self._axes_pad))
341
349
if v :
342
350
v .append (self ._vert_pad_size )
@@ -362,6 +370,10 @@ def _get_col_row(self, n):
362
370
363
371
return col , row
364
372
373
+ # Good to propagate __len__ if we have __getitem__
374
+ def __len__ (self ):
375
+ return len (self .axes_all )
376
+
365
377
def __getitem__ (self , i ):
366
378
return self .axes_all [i ]
367
379
@@ -376,11 +388,19 @@ def set_axes_pad(self, axes_pad):
376
388
"set axes_pad"
377
389
self ._axes_pad = axes_pad
378
390
379
- self ._horiz_pad_size .fixed_size = axes_pad
380
- self ._vert_pad_size .fixed_size = axes_pad
391
+ # These two lines actually differ from ones in _init_axes_pad
392
+ self ._horiz_pad_size .fixed_size = axes_pad [0 ]
393
+ self ._vert_pad_size .fixed_size = axes_pad [1 ]
381
394
382
395
def get_axes_pad (self ):
383
- "get axes_pad"
396
+ """
397
+ get axes_pad
398
+
399
+ Returns
400
+ -------
401
+ tuple
402
+ Padding in inches, (horizontal pad, vertical pad)
403
+ """
384
404
return self ._axes_pad
385
405
386
406
def set_aspect (self , aspect ):
@@ -484,6 +504,8 @@ def __init__(self, fig,
484
504
================ ======== =========================================
485
505
direction "row" [ "row" | "column" ]
486
506
axes_pad 0.02 float| pad between axes given in inches
507
+ or tuple-like of floats,
508
+ (horizontal padding, vertical padding)
487
509
add_all True [ True | False ]
488
510
share_all False [ True | False ]
489
511
aspect True [ True | False ]
@@ -510,12 +532,17 @@ def __init__(self, fig,
510
532
511
533
10000
self .ngrids = ngrids
512
534
535
+ axes_pad = _extend_axes_pad (axes_pad )
513
536
self ._axes_pad = axes_pad
514
537
515
538
self ._colorbar_mode = cbar_mode
516
539
self ._colorbar_location = cbar_location
517
540
if cbar_pad is None :
518
- self ._colorbar_pad = axes_pad
541
+ # horizontal or vertical arrangement?
542
+ if cbar_location in ("left" , "right" ):
543
+ self ._colorbar_pad = axes_pad [0 ]
544
+ else :
545
+ self ._colorbar_pad = axes_pad [1 ]
519
546
else :
520
547
self ._colorbar_pad = cbar_pad
521
548
@@ -538,8 +565,8 @@ def __init__(self, fig,
538
565
axes_class , axes_class_args = axes_class
539
566
540
567
self .axes_all = []
541
- self .axes_column = [[] for i in range (self ._ncols )]
542
- self .axes_row = [[] for i in range (self ._nrows )]
568
+ self .axes_column = [[] for _ in range (self ._ncols )]
569
+ self .axes_row = [[] for _ in range (self ._nrows )]
543
570
544
571
self .cbar_axes = []
545
572
@@ -563,8 +590,8 @@ def __init__(self, fig,
563
590
rect = self ._divider .get_position ()
564
591
565
592
# reference axes
566
- self ._column_refax = [None for i in range (self ._ncols )]
567
- self ._row_refax = [None for i in range (self ._nrows )]
593
+ self ._column_refax = [None for _ in range (self ._ncols )]
594
+ self ._row_refax = [None for _ in range (self ._nrows )]
568
595
self ._refax = None
569
596
570
597
for i in range (self .ngrids ):
@@ -678,7 +705,7 @@ def _update_locators(self):
678
705
v_cb_pos = []
679
706
for row , ax in enumerate (self .axes_column [0 ][::- 1 ]):
680
707
if v :
681
- v .append (self ._horiz_pad_size ) # Size.Fixed(self._axes_pad))
708
+ v .append (self ._vert_pad_size ) # Size.Fixed(self._axes_pad))
682
709
683
710
if ax :
684
711
sz = Size .AxesY (ax , aspect = "axes" , ref_ax = self .axes_all [0 ])
@@ -786,7 +813,7 @@ def _update_locators(self):
786
813
F .subplots_adjust (left = 0.15 , right = 0.9 )
787
814
788
815
grid = Grid (F , 111 , # similar to subplot(111)
789
- nrows_ncols = (2 , 2 ),
816
+ nrows_ncols = (2 , 2 ),
790
817
direction = "row" ,
791
818
axes_pad = 0.05 ,
792
819
add_all = True ,
@@ -802,12 +829,12 @@ def _update_locators(self):
802
829
F .subplots_adjust (left = 0.05 , right = 0.98 )
803
830
804
831
grid = ImageGrid (F , 131 , # similar to subplot(111)
805
- nrows_ncols = (2 , 2 ),
806
- direction = "row" ,
807
- axes_pad = 0.05 ,
808
- add_all = True ,
809
- label_mode = "1" ,
810
- )
832
+ nrows_ncols = (2 , 2 ),
833
+ direction = "row" ,
834
+ axes_pad = 0.05 ,
835
+ add_all = True ,
836
+ label_mode = "1" ,
837
+ )
811
838
812
839
Z , extent = get_demo_image ()
813
840
plt .ioff ()
@@ -821,14 +848,14 @@ def _update_locators(self):
821
848
plt .ion ()
822
849
823
850
grid = ImageGrid (F , 132 , # similar to subplot(111)
824
- nrows_ncols = (2 , 2 ),
825
- direction = "row" ,
826
- axes_pad = 0.0 ,
827
- add_all = True ,
828
- share_all = True ,
829
- label_mode = "1" ,
830
- cbar_mode = "single" ,
831
- )
851
+ nrows_ncols = (2 , 2 ),
852
+ direction = "row" ,
853
+ axes_pad = 0.0 ,
854
+ add_all = True ,
855
+ share_all = True ,
856
+ label_mode = "1" ,
857
+ cbar_mode = "single" ,
858
+ )
832
859
833
860
Z , extent = get_demo_image ()
834
861
plt .ioff ()
@@ -844,17 +871,17 @@ def _update_locators(self):
844
871
plt .ion ()
845
872
846
873
grid = ImageGrid (F , 133 , # similar to subplot(122)
847
- nrows_ncols = (2 , 2 ),
848
- direction = "row" ,
849
- axes_pad = 0.1 ,
850
- add_all = True ,
851
- label_mode = "1" ,
852
- share_all = True ,
853
- cbar_location = "top" ,
854
- cbar_mode = "each" ,
855
- cbar_size = "7%" ,
856
- cbar_pad = "2%" ,
857
- )
874
+ nrows_ncols = (2 , 2 ),
875
+ direction = "row" ,
876
+ axes_pad = 0.1 ,
877
+ add_all = True ,
878
+ label_mode = "1" ,
879
+ share_all = True ,
880
+ cbar_location = "top" ,
881
+ cbar_mode = "each" ,
882
+ cbar_size = "7%" ,
883
+ cbar_pad = "2%" ,
884
+ )
858
885
plt .ioff ()
859
886
for i in range (4 ):
860
887
im = grid [i ].imshow (Z , extent = extent , interpolation = "nearest" )
0 commit comments