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

Skip to content

Commit 751e141

Browse files
committed
honour panchor keyword for colorbar on subplot
1 parent 028f07c commit 751e141

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

lib/matplotlib/colorbar.py

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

16191619
parent.set_subplotspec(ss_main)
1620-
parent.set_anchor(loc_settings["panchor"])
1620+
if panchor is not False:
1621+
parent.set_anchor(panchor)
16211622

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

lib/matplotlib/tests/test_colorbar.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,20 @@ def test_colorbar_positioning(use_gridspec):
211211

212212

213213
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.
214+
# Note that this differs from the tests above with panchor=False because
215+
# there use_gridspec is actually ineffective: passing *ax* as lists always
216+
# disables use_gridspec.
217+
ax = plt.subplot(111, anchor='N')
217218
plt.imshow([[0, 1]])
218219
plt.colorbar(panchor=False)
220+
assert ax.get_anchor() == 'N'
221+
222+
223+
def test_colorbar_single_ax_panchor_east():
224+
ax = plt.subplot(111, anchor='N')
225+
plt.imshow([[0, 1]])
226+
plt.colorbar(panchor='E')
227+
assert ax.get_anchor() == 'E'
219228

220229

221230
@image_comparison(['contour_colorbar.png'], remove_text=True)

0 commit comments

Comments
 (0)