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

Skip to content

Commit bdc427a

Browse files
committed
Merge pull request #540 from mdboom/issue540
Raise a useful error message when there is no current image
2 parents 346615e + bd5c5b4 commit bdc427a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

lib/matplotlib/pyplot.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,8 @@ def colormaps():
16821682
def colorbar(mappable=None, cax=None, ax=None, **kw):
16831683
if mappable is None:
16841684
mappable = gci()
1685+
if mappable is None:
1686+
raise RuntimeError('You must first define an image, eg with imshow')
16851687
if ax is None:
16861688
ax = gca()
16871689

@@ -1732,6 +1734,9 @@ def set_cmap(cmap):
17321734

17331735
if im is not None:
17341736
im.set_cmap(cmap)
1737+
else:
1738+
raise RuntimeError('You must first define an image, eg with imshow')
1739+
17351740
draw_if_interactive()
17361741

17371742

0 commit comments

Comments
 (0)