Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX: colorbar pad for ImageGrid #28525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/users/next_whats_new/mpl_toolkit_colorbar_pad.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Fix padding of single colorbar for ``ImageGrid``
------------------------------------------------

``ImageGrid`` with ``cbar_mode="single"`` no longer adds the ``axes_pad`` between the

Check warning on line 4 in doc/users/next_whats_new/mpl_toolkit_colorbar_pad.rst

View workflow job for this annotation

GitHub Actions / sphinx

[sphinx] doc/users/next_whats_new/mpl_toolkit_colorbar_pad.rst#L4

py:obj reference target not found: cbar_pad
Raw output
doc/users/next_whats_new/mpl_toolkit_colorbar_pad.rst:4: WARNING: py:obj reference target not found: cbar_pad
axes and the colorbar for thr ``cbar_location`` left and bottom. Add required space
using `cbar_pad` instead.
9 changes: 7 additions & 2 deletions lib/mpl_toolkits/axes_grid1/axes_grid.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from numbers import Number
import functools
from types import MethodType
Expand Down Expand Up @@ -358,6 +358,11 @@
cbar_location : {"left", "right", "bottom", "top"}, default: "right"
cbar_pad : float, default: None
Padding between the image axes and the colorbar axes.

.. versionchanged:: 3.10
`cbar_mode="single"` no longer adds the `axes_pad` between the axes and
the colorbar if the `cbar_location` is `"left"` or `"bottom"`

cbar_size : size specification (see `.Size.from_any`), default: "5%"
Colorbar size.
cbar_set_cax : bool, default: True
Expand Down Expand Up @@ -439,7 +444,7 @@
self.cbar_axes[0].set_visible(True)

for col, ax in enumerate(self.axes_row[0]):
if h:
if col != 0:
h.append(self._horiz_pad_size)

if ax:
Expand Down Expand Up @@ -468,7 +473,7 @@
v_ax_pos = []
v_cb_pos = []
for row, ax in enumerate(self.axes_column[0][::-1]):
if v:
if row != 0:
v.append(self._vert_pad_size)

if ax:
Expand Down
2 changes: 1 addition & 1 deletion lib/mpl_toolkits/axes_grid1/tests/test_axes_grid1.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ def test_image_grid_single_bottom():

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