diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index 89c86981d3ff..c59b0ac815fe 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -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="") diff --git a/lib/matplotlib/tests/test_colorbar.py b/lib/matplotlib/tests/test_colorbar.py index 20d94c1ac3a7..d95e15903f51 100644 --- a/lib/matplotlib/tests/test_colorbar.py +++ b/lib/matplotlib/tests/test_colorbar.py @@ -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))