17
17
from matplotlib .gridspec import SubplotSpec , GridSpec
18
18
19
19
from .axes_divider import Size , SubplotDivider , LocatableAxes , Divider
20
+
20
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
21
28
22
29
def _tick_only (ax , bottom_on , left_on ):
23
30
bottom_off = not bottom_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 ]
@@ -310,10 +319,11 @@ 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
@@ -376,11 +386,19 @@ def set_axes_pad(self, axes_pad):
376
386
"set axes_pad"
377
387
self ._axes_pad = axes_pad
378
388
379
- self ._horiz_pad_size .fixed_size = axes_pad
380
- self ._vert_pad_size .fixed_size = axes_pad
389
+ # These two lines actually differ from ones in _init_axes_pad
390
+ self ._horiz_pad_size .fixed_size = axes_pad [0 ]
391
+ self ._vert_pad_size .fixed_size = axes_pad [1 ]
381
392
382
393
def get_axes_pad (self ):
383
- "get axes_pad"
394
+ """
395
+ get axes_pad
396
+
397
+ Returns
398
+ -------
399
+ tuple
400
+ Padding in inches, (horizontal pad, vertical pad)
401
+ """
384
402
return self ._axes_pad
385
403
386
404
def set_aspect (self , aspect ):
@@ -484,6 +502,8 @@ def __init__(self, fig,
484
502
================ ======== =========================================
485
503
direction "row" [ "row" | "column" ]
486
504
axes_pad 0.02 float| pad between axes given in inches
505
+ or tuple-like of floats,
506
+ (horizontal padding, vertical padding)
487
507
add_all True [ True | False ]
488
508
share_all False [ True | False ]
489
509
aspect True [ True | False ]
@@ -510,12 +530,15 @@ def __init__(self, fig,
510
530
511
531
self .ngrids = ngrids
512
532
533
+ axes_pad = _extend_axes_pad (axes_pad )
513
534
self ._axes_pad = axes_pad
514
535
515
536
self ._colorbar_mode = cbar_mode
516
537
self ._colorbar_location = cbar_location
517
538
if cbar_pad is None :
518
- self ._colorbar_pad = axes_pad
539
+ # horizontal or vertical arrangement?
540
+ self ._colorbar_pad = axes_pad [0 ] \
541
+ if cbar_location in ("left" , "right" ) else axes_pad [1 ]
519
542
else :
520
543
self ._colorbar_pad = cbar_pad
521
544
@@ -678,7 +701,7 @@ def _update_locators(self):
678
701
v_cb_pos = []
679
702
for row , ax in enumerate (self .axes_column [0 ][::- 1 ]):
680
703
if v :
681
- v .append (self ._horiz_pad_size ) # Size.Fixed(self._axes_pad))
704
+ v .append (self ._vert_pad_size ) # Size.Fixed(self._axes_pad))
682
705
683
706
if ax :
684
707
sz = Size .AxesY (ax , aspect = "axes" , ref_ax = self .axes_all [0 ])
0 commit comments