Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c5b70cb

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

File tree

Expand file treeCollapse file tree

2 files changed

+15
-1
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+15
-1
lines changed

‎lib/matplotlib/figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.py
+6-1Lines 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

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_colorbar.py
+9Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.