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

Skip to content

Fix colorbar stealing from a single axes and with panchor=False. #22776

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
Apr 4, 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
2 changes: 1 addition & 1 deletion lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,7 @@ def make_axes_gridspec(parent, *, location=None, orientation=None,
aspect = 1 / aspect

parent.set_subplotspec(ss_main)
parent.set_anchor(panchor)
parent.set_anchor(loc_settings["panchor"])

fig = parent.get_figure()
cax = fig.add_subplot(ss_cb, label="<colorbar>")
Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ def test_colorbar_positioning(use_gridspec):
anchor=(0.8, 0.5), shrink=0.6, use_gridspec=use_gridspec)


def test_colorbar_single_ax_panchor_false():
# Just smoketesting that this doesn't crash. Note that this differs from
# the tests above with panchor=False because there use_gridspec is actually
# ineffective: passing *ax* as lists always disable use_gridspec.
plt.imshow([[0, 1]])
plt.colorbar(panchor=False)


@image_comparison(['contour_colorbar.png'], remove_text=True)
def test_contour_colorbar():
fig, ax = plt.subplots(figsize=(4, 2))
Expand Down