Skip to content

Commit 095b970

Browse files
committed
FIX: colorbar pad for ImageGrid
1 parent fa16860 commit 095b970

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Fix padding of single colorbar for ``ImageGrid``
2+
------------------------------------------------
3+
4+
``ImageGrid`` with ``cbar_mode="single"`` no longer adds the ``axes_pad`` between the
5+
axes and the colorbar for thr ``cbar_location`` left and bottom. Add required space
6+
using `cbar_pad` instead.

lib/mpl_toolkits/axes_grid1/axes_grid.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,11 @@ def __init__(self, fig,
358358
cbar_location : {"left", "right", "bottom", "top"}, default: "right"
359359
cbar_pad : float, default: None
360360
Padding between the image axes and the colorbar axes.
361+
362+
.. versionchanged:: 3.10
363+
`cbar_mode="single"` no longer adds the `axes_pad` between the axes and
364+
the colorbar if the `cbar_location` is `"left"` or `"bottom"`
365+
361366
cbar_size : size specification (see `.Size.from_any`), default: "5%"
362367
Colorbar size.
363368
cbar_set_cax : bool, default: True
@@ -439,7 +444,7 @@ def _init_locators(self):
439444
self.cbar_axes[0].set_visible(True)
440445

441446
for col, ax in enumerate(self.axes_row[0]):
442-
if h:
447+
if col != 0:
443448
h.append(self._horiz_pad_size)
444449

445450
if ax:
@@ -468,7 +473,7 @@ def _init_locators(self):
468473
v_ax_pos = []
469474
v_cb_pos = []
470475
for row, ax in enumerate(self.axes_column[0][::-1]):
471-
if v:
476+
if row != 0:
472477
v.append(self._vert_pad_size)
473478

474479
if ax:

lib/mpl_toolkits/axes_grid1/tests/test_axes_grid1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def test_image_grid_single_bottom():
424424

425425
fig = plt.figure(1, (2.5, 1.5))
426426
grid = ImageGrid(fig, (0, 0, 1, 1), nrows_ncols=(1, 3),
427-
axes_pad=(0.2, 0.15), cbar_mode="single",
427+
axes_pad=(0.2, 0.15), cbar_mode="single", cbar_pad=0.3,
428428
cbar_location="bottom", cbar_size="10%", label_mode="1")
429429
# 4-tuple rect => Divider, isinstance will give True for SubplotDivider
430430
assert type(grid.get_divider()) is Divider

0 commit comments

Comments
 (0)