10000 FIX: Colorbars check for subplotspec attribute before using by greglucas · Pull Request #22611 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

FIX: Colorbars check for subplotspec attribute before using #22611

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 1 commit into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 3 additions & 5 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,10 @@ def get_subplotspec(self):
# make tight_layout happy..
ss = getattr(self._cbar.ax, 'get_subplotspec', None)
if ss is None:
if self._orig_locator is None:
if not hasattr(self._orig_locator, "get_subplotspec"):
return None
ss = self._orig_locator.get_subplotspec()
else:
ss = ss()
return ss
ss = self._orig_locator.get_subplotspec
return ss()


@docstring.Substitution(_colormap_kw_doc)
Expand Down
12 changes: 12 additions & 0 deletions lib/mpl_toolkits/tests/test_axes_grid1.py
8D54
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ def test_axesgrid_colorbar_log_smoketest():
grid.cbar_axes[0].colorbar(im)


def test_inset_colorbar_tight_layout_smoketest():
fig, ax = plt.subplots(1, 1)
pts = ax.scatter([0, 1], [0, 1], c=[1, 5])

cax = inset_axes(ax, width="3%", height="70%")
plt.colorbar(pts, cax=cax)

with pytest.warns(UserWarning, match="This figure includes Axes"):
# Will warn, but not raise an error
plt.tight_layout()


@image_comparison(['inset_locator.png'], style='default', remove_text=True)
def test_inset_locator():
fig, ax = plt.subplots(figsize=[5, 4])
Expand Down
0