From b528281eb15446f5b585152d7eac9e82d1bf45d8 Mon Sep 17 00:00:00 2001 From: Paul Ivanov Date: Fri, 16 Nov 2012 17:42:07 -0800 Subject: [PATCH] set_cmap should not require an active image Before this commit, it was not possible to change the default colormap if there wasn't an active colorable artist, i.e. if plt.gci() returned None. There's no reason why we should force this, though, since part of what plt.set_cmap does is setting the default colormap for all FUTURE colorable artists which will be created. Colormaps which are currently exposed as their own functions in pyplot, such as plt.gray(), plt.hsv(), plt.hot() and plt.jet() make no such restriction, they do not complain if plt.gci() happens to return None. Prior to this commit ``` In [2]: plt.set_cmap('bwr') --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) in () ----> 1 plt.set_cmap('bwr') /home/pi/.local/lib/python2.7/site-packages/matplotlib/pyplot.pyc in set_cmap(cmap) 2029 im.set_cmap(cmap) 2030 else: -> 2031 raise RuntimeError('You must first define an image, eg with imshow') 2032 2033 draw_if_interactive() RuntimeError: You must first define an image, eg with imshow In [3]: ``` After this commit, no error is thrown, and the appropriate colormap is activated. ``` In [2]: plt.set_cmap('bwr') In [3]: ``` --- CHANGELOG | 4 ++++ lib/matplotlib/pyplot.py | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 19f1e06299fc..962f26200497 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +2012-11-16 plt.set_cmap no longer throws errors if there is not already + an active colorable artist, such as an image, and just sets + up the colormap to use from that point forward. - PI + 2012-11-13 Add a symmetric log normalization class to colors.py. Also added some tests for the normalization class. Till Stensitzki diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 4dd2f44504ba..7e919336936c 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -2027,8 +2027,6 @@ def set_cmap(cmap): if im is not None: im.set_cmap(cmap) - else: - raise RuntimeError('You must first define an image, eg with imshow') draw_if_interactive()