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

Skip to content

set_cmap should not require an active image #1515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2012

Conversation

ivanov
Copy link
Member

@ivanov ivanov commented Nov 17, 2012

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)
<ipython-input-2-fa42f8679abe> in <module>()
----> 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]:

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)
<ipython-input-2-fa42f8679abe> in <module>()
----> 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]:
```
@dmcdougall
Copy link
Member

@ivanov Thanks.

The Travis failure is a dud. Merging.

dmcdougall added a commit that referenced this pull request Nov 26, 2012
set_cmap should not require an active image
@dmcdougall dmcdougall merged commit 7b3996e into matplotlib:master Nov 26, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants