8000 Merge pull request #10000 from timhoffm/fix-figure-colorbar · matplotlib/matplotlib@c5b70cb · GitHub
[go: up one dir, main page]

Skip to content

Commit c5b70cb

Browse files
authored
Merge pull request #10000 from timhoffm/fix-figure-colorbar
Fix figure.colorbar() with axes keywords
2 parents 7231bd3 + 9ef39d6 commit c5b70cb

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/matplotlib/figure.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,12 @@ def colorbar(self, mappable, cax=None, ax=None, use_gridspec=True, **kw):
19091909
else:
19101910
cax, kw = cbar.make_axes(ax, **kw)
19111911
cax._hold = True
1912-
cb = cbar.colorbar_factory(cax, mappable, **kw)
1912+
1913+
# need to remove kws that cannot be passed to Colorbar
1914+
NON_COLORBAR_KEYS = ['fraction', 'pad', 'shrink', 'aspect', 'anchor',
1915+
'panchor']
1916+
cb_kw = {k: v for k, v in kw.items() if k not in NON_COLORBAR_KEYS}
1917+
cb = cbar.colorbar_factory(cax, mappable, **cb_kw)
19131918

19141919
self.sca(current_ax)
19151920
self.stale = True

lib/matplotlib/tests/test_colorbar.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,12 @@ def test_colorbar_lognorm_extension():
306306
cb = ColorbarBase(ax, norm=LogNorm(vmin=0.1, vmax=1000.0),
307307
orientation='vertical', extend='both')
308308
assert cb._values[0] >= 0.0
309+
310+
311+
def test_colorbar_axes_kw():
312+
# test fix for #8493: This does only test, that axes-related keywords pass
313+
# and do not raise an exception.
314+
plt.figure()
315+
plt.imshow(([[1, 2], [3, 4]]))
316+
plt.colorbar(orientation='horizontal', fraction=0.2, pad=0.2, shrink=0.5,
317+
aspect=10, anchor=(0., 0.), panchor=(0., 1.))

0 commit comments

Comments
 (0)
0