Skip to content
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

Generate reversed ListedColormaps #5092

Merged
merged 2 commits into from Sep 17, 2015
Merged

Generate reversed ListedColormaps #5092

merged 2 commits into from Sep 17, 2015

Conversation

cgohlke
Copy link
Contributor

@cgohlke cgohlke commented Sep 16, 2015

This example currently fails with 1.5.0rc1:

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> plt.imshow(np.random.rand(64, 64), cmap='viridis_r')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "X:\Python27\lib\site-packages\matplotlib\pyplot.py", line 3024, in imshow
    **kwargs)
  File "X:\Python27\lib\site-packages\matplotlib\__init__.py", line 1806, in inner
    return func(ax, *args, **kwargs)
  File "X:\Python27\lib\site-packages\matplotlib\axes\_axes.py", line 4940, in imshow
    resample=resample, **kwargs)
  File "X:\Python27\lib\site-packages\matplotlib\image.py", line 597, in __init__
    **kwargs
  File "X:\Python27\lib\site-packages\matplotlib\image.py", line 109, in __init__
    cm.ScalarMappable.__init__(self, norm, cmap)
  File "X:\Python27\lib\site-packages\matplotlib\cm.py", line 202, in __init__
    self.cmap = get_cmap(cmap)
  File "X:\Python27\lib\site-packages\matplotlib\cm.py", line 167, in get_cmap
    % (name, ', '.join(cmap_d.keys())))
ValueError: Colormap viridis_r is not recognized. Possible values are: Spectral, <snip>

This PR generates the 'viridis_r', 'plasma_r', 'inferno_r', and 'magma_r' colormaps.

@tacaswell tacaswell added this to the next point release (1.5.0) milestone Sep 16, 2015
@@ -1036,3 +1036,7 @@
('viridis', _viridis_data)):

cmaps[name] = ListedColormap(data, name=name)
# generate reversed colormap
name = name + '_r'
data = [rgb for rgb in reversed(data)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor condensation: I would use data = list(reversed(data))

pelson added a commit that referenced this pull request Sep 17, 2015
Generate reversed ListedColormaps
@pelson pelson merged commit b9710e6 into matplotlib:master Sep 17, 2015
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.

None yet

4 participants