Skip to content

FIX: colorbar check for constrained layout #10594

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 2 commits into from
Feb 25, 2018
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: 6 additions & 2 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1132,8 +1132,12 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
parents = np.atleast_1d(parents).ravel()

# check if using constrained_layout:
gs = parents[0].get_subplotspec().get_gridspec()
using_constrained_layout = (gs._layoutbox is not None)
try:
gs = parents[0].get_subplotspec().get_gridspec()
using_constrained_layout = (gs._layoutbox is not None)
except AttributeError:
using_constrained_layout = False

# defaults are not appropriate for constrained_layout:
pad0 = loc_settings['pad']
if using_constrained_layout:
Expand Down
11 changes: 11 additions & 0 deletions lib/matplotlib/tests/test_constrainedlayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,3 +377,14 @@ def test_constrained_layout19():
ax.set_title('')
fig.canvas.draw()
assert all(ax.get_position().extents == ax2.get_position().extents)


def test_constrained_layout20():
'Smoke test cl does not mess up added axes'
gx = np.linspace(-5, 5, 4)
img = np.hypot(gx, gx[:, None])

fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1])
mesh = ax.pcolormesh(gx, gx, img)
fig.colorbar(mesh)