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

Skip to content

Commit ff34c60

Browse files
authored
Merge pull request #22776 from anntzer/sacpf
Fix colorbar stealing from a single axes and with panchor=False.
2 parents 4f5b310 + 357979e commit ff34c60

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/matplotlib/colorbar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1617,7 +1617,7 @@ def make_axes_gridspec(parent, *, location=None, orientation=None,
16171617
aspect = 1 / aspect
16181618

16191619
parent.set_subplotspec(ss_main)
1620-
parent.set_anchor(panchor)
1620+
parent.set_anchor(loc_settings["panchor"])
16211621

16221622
fig = parent.get_figure()
16231623
cax = fig.add_subplot(ss_cb, label="<colorbar>")

lib/matplotlib/tests/test_colorbar.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ def test_colorbar_positioning(use_gridspec):
210210
anchor=(0.8, 0.5), shrink=0.6, use_gridspec=use_gridspec)
211211

212212

213+
def test_colorbar_single_ax_panchor_false():
214+
# Just smoketesting that this doesn't crash. Note that this differs from
215+
# the tests above with panchor=False because there use_gridspec is actually
216+
# ineffective: passing *ax* as lists always disable use_gridspec.
217+
plt.imshow([[0, 1]])
218+
plt.colorbar(panchor=False)
219+
220+
213221
@image_comparison(['contour_colorbar.png'], remove_text=True)
214222
def test_contour_colorbar():
215223
fig, ax = plt.subplots(figsize=(4, 2))

0 commit comments

Comments
 (0)