Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion python/lsst/display/matplotlib/matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def __init__(self, display, verbose=False, interpretMaskBits=True, mtvOrigin=afw
self._interpretMaskBits = interpretMaskBits # interpret mask bits in mtv
self._mtvOrigin = mtvOrigin
self._mappable = None
self._image_colormap = pyplot.cm.gray
#
self.__alpha = unicodedata.lookup("GREEK SMALL LETTER alpha") # used in cursor display string
self.__delta = unicodedata.lookup("GREEK SMALL LETTER delta") # used in cursor display string
Expand Down Expand Up @@ -148,6 +149,29 @@ def show_colorbar(self, show=True):
if show:
if self._mappable:
self._figure.colorbar(self._mappable)

def _setImageColormap(self, cmap):
"""Set the colormap used for the image

cmap should be either the name of an attribute of pyplot.cm or an mpColors.Colormap
(e.g. "gray" or pyplot.cm.gray)

"""
if not isinstance(cmap, mpColors.Colormap):
cmap = getattr(pyplot.cm, cmap)

self._image_colormap = cmap

# This will be moved into Display (DM-15218)
def setImageColormap(self, cmap):
"""Set the colormap used for the image

cmap is a string to be interpreted by the backend; where possible
a string such as "gray" will be honoured, but backend
specific values are also permitted
"""
self._setImageColormap(cmap)

#
# Defined API
#
Expand Down Expand Up @@ -279,7 +303,7 @@ def _i_mtv(self, data, wcs, title, isMask):
cmap = mpColors.ListedColormap(colors)
norm = mpColors.NoNorm()
else:
cmap = pyplot.cm.gray
cmap = self._image_colormap
norm = self._normalize

ax = self._figure.gca()
Expand Down
11 changes: 11 additions & 0 deletions tests/test_display_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ def testSetAfwDisplayBackend(self):
"""Set the default backend to this package"""
afwDisplay.setDefaultBackend("matplotlib")

def testSetImageColormap(self):
"""This is a stand-in for an eventual testcase for changing image colormap
The basic outline should look something like:

afwDisplay.setDefaultBackend("matplotlib")
display = afwDisplay.Display()
display.setImageColormap('viridis')
assert display._image_colormap == 'viridis'
"""
pass

class TestMemory(lsst.utils.tests.MemoryTestCase):
pass

Expand Down