Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4bcc2ca

Browse filesBrowse files
authored
Merge pull request #28525 from mathause/fix_imagegrid_cbar_pad
FIX: colorbar pad for `ImageGrid`
2 parents e5225b4 + eade1da commit 4bcc2ca
Copy full SHA for 4bcc2ca

File tree

3 files changed

+14
-3
lines changed
Filter options

3 files changed

+14
-3
lines changed
+6Lines 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 ``cbar_location`` "left" and "bottom". If desired, add additional spacing
6+
using ``cbar_pad``.

‎lib/mpl_toolkits/axes_grid1/axes_grid.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/axes_grid1/axes_grid.py
+7-2Lines 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 *axes_pad* between the axes
364+
and 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

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/axes_grid1/tests/test_axes_grid1.py
+1-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.