Skip to content

Commit f5f44d9

Browse files
committed
implemented separate horizontal/vertical axes padding
1 parent 92f5e91 commit f5f44d9

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

lib/mpl_toolkits/axes_grid1/axes_grid.py

+30-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@
1717
from matplotlib.gridspec import SubplotSpec, GridSpec
1818

1919
from .axes_divider import Size, SubplotDivider, LocatableAxes, Divider
20+
2021

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
2128

2229
def _tick_only(ax, bottom_on, left_on):
2330
bottom_off = not bottom_on
@@ -200,6 +207,8 @@ def __init__(self, fig,
200207
================ ======== =========================================
201208
direction "row" [ "row" | "column" ]
202209
axes_pad 0.02 float| pad between axes given in inches
210+
or tuple-like of floats,
211+
(horizontal padding, vertical padding)
203212
add_all True [ True | False ]
204213
share_all False [ True | False ]
205214
share_x True [ True | False ]
@@ -310,10 +319,11 @@ def __init__(self, fig,
310319
self.set_label_mode(label_mode)
311320

312321
def _init_axes_pad(self, axes_pad):
322+
axes_pad = _extend_axes_pad(axes_pad)
313323
self._axes_pad = axes_pad
314324

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])
317327

318328
def _update_locators(self):
319329

@@ -376,11 +386,19 @@ def set_axes_pad(self, axes_pad):
376386
"set axes_pad"
377387
self._axes_pad = axes_pad
378388

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]
381392

382393
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+
"""
384402
return self._axes_pad
385403

386404
def set_aspect(self, aspect):
@@ -484,6 +502,8 @@ def __init__(self, fig,
484502
================ ======== =========================================
485503
direction "row" [ "row" | "column" ]
486504
axes_pad 0.02 float| pad between axes given in inches
505+
or tuple-like of floats,
506+
(horizontal padding, vertical padding)
487507
add_all True [ True | False ]
488508
share_all False [ True | False ]
489509
aspect True [ True | False ]
@@ -510,12 +530,15 @@ def __init__(self, fig,
510530

511531
self.ngrids = ngrids
512532

533+
axes_pad = _extend_axes_pad(axes_pad)
513534
self._axes_pad = axes_pad
514535

515536
self._colorbar_mode = cbar_mode
516537
self._colorbar_location = cbar_location
517538
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]
519542
else:
520543
self._colorbar_pad = cbar_pad
521544

@@ -678,7 +701,7 @@ def _update_locators(self):
678701
v_cb_pos = []
679702
for row, ax in enumerate(self.axes_column[0][::-1]):
680703
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))
682705

683706
if ax:
684707
sz = Size.AxesY(ax, aspect="axes", ref_ax=self.axes_all[0])

0 commit comments

Comments
 (0)