From bc9a3e76c47d5e9ebdba0ab207fe9e30de91efd5 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 14 Dec 2017 01:47:54 +0100 Subject: [PATCH 1/2] fix figure.colorbar() with axes keywords --- lib/matplotlib/figure.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index e3d86e3f8438..f65ab2005daa 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -1891,7 +1891,12 @@ def colorbar(self, mappable, cax=None, ax=None, use_gridspec=True, **kw): else: cax, kw = cbar.make_axes(ax, **kw) cax._hold = True - cb = cbar.colorbar_factory(cax, mappable, **kw) + + # need to remove kws that cannot be passed to Colorbar + NON_COLORBAR_KEYS = ['fraction', 'pad', 'shrink', 'aspect', 'anchor', + 'panchor'] + cb_kw = {k: v for k, v in kw.items() if k not in NON_COLORBAR_KEYS} + cb = cbar.colorbar_factory(cax, mappable, **cb_kw) self.sca(current_ax) self.stale = True From 9ef39d65ac876e37c569a5835abd57ae401082bf Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Sun, 17 Dec 2017 18:08:10 +0100 Subject: [PATCH 2/2] add test for axes keywords on colorbar() --- lib/matplotlib/tests/test_colorbar.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/matplotlib/tests/test_colorbar.py b/lib/matplotlib/tests/test_colorbar.py index b75ba7e9f23d..32d4dd87f1e7 100644 --- a/lib/matplotlib/tests/test_colorbar.py +++ b/lib/matplotlib/tests/test_colorbar.py @@ -306,3 +306,12 @@ def test_colorbar_lognorm_extension(): cb = ColorbarBase(ax, norm=LogNorm(vmin=0.1, vmax=1000.0), orientation='vertical', extend='both') assert cb._values[0] >= 0.0 + + +def test_colorbar_axes_kw(): + # test fix for #8493: This does only test, that axes-related keywords pass + # and do not raise an exception. + plt.figure() + plt.imshow(([[1, 2], [3, 4]])) + plt.colorbar(orientation='horizontal', fraction=0.2, pad=0.2, shrink=0.5, + aspect=10, anchor=(0., 0.), panchor=(0., 1.))