diff --git a/examples/ImageView.py b/examples/ImageView.py index 22168409..881d8cdd 100644 --- a/examples/ImageView.py +++ b/examples/ImageView.py @@ -48,6 +48,18 @@ data[:,50:60,50:60] += sig ## Display the data and assign each frame a time value from 1.0 to 3.0 imv.setImage(data, xvals=np.linspace(1., 3., data.shape[0])) +## Set a custom color map +colors = [ + (0, 0, 0), + (45, 5, 61), + (84, 42, 55), + (150, 87, 60), + (208, 171, 141), + (255, 255, 255) +] +cmap = pg.ColorMap(pos=np.linspace(0.0, 1.0, 6), color=colors) +imv.setColorMap(cmap) + ## Start Qt event loop unless running in interactive mode. if __name__ == '__main__': import sys diff --git a/pyqtgraph/graphicsItems/GradientEditorItem.py b/pyqtgraph/graphicsItems/GradientEditorItem.py index 5a7ca211..6ce06b61 100644 --- a/pyqtgraph/graphicsItems/GradientEditorItem.py +++ b/pyqtgraph/graphicsItems/GradientEditorItem.py @@ -13,7 +13,6 @@ from ..python2_3 import cmp __all__ = ['TickSliderItem', 'GradientEditorItem'] - Gradients = OrderedDict([ ('thermal', {'ticks': [(0.3333, (185, 0, 0, 255)), (0.6666, (255, 220, 0, 255)), (1, (255, 255, 255, 255)), (0, (0, 0, 0, 255))], 'mode': 'rgb'}), ('flame', {'ticks': [(0.2, (7, 0, 220, 255)), (0.5, (236, 0, 134, 255)), (0.8, (246, 246, 0, 255)), (1.0, (255, 255, 255, 255)), (0.0, (0, 0, 0, 255))], 'mode': 'rgb'}), @@ -25,6 +24,13 @@ Gradients = OrderedDict([ ('grey', {'ticks': [(0.0, (0, 0, 0, 255)), (1.0, (255, 255, 255, 255))], 'mode': 'rgb'}), ]) +def addGradientListToDocstring(): + """Decorator to add list of current pre-defined gradients to the end of a function docstring.""" + def dec(fn): + fn.__doc__ = fn.__doc__ + str(Gradients.keys()).strip('[').strip(']') + return fn + return dec + class TickSliderItem(GraphicsWidget): @@ -471,11 +477,12 @@ class GradientEditorItem(TickSliderItem): act = self.sender() self.loadPreset(act.name) + @addGradientListToDocstring() def loadPreset(self, name): """ - Load a predefined gradient. - - """ ## TODO: provide image with names of defined gradients + Load a predefined gradient. Currently defined gradients are: + """## TODO: provide image with names of defined gradients + #global Gradients self.restoreState(Gradients[name]) diff --git a/pyqtgraph/imageview/ImageView.py b/pyqtgraph/imageview/ImageView.py index 61193fc4..27e64c4c 100644 --- a/pyqtgraph/imageview/ImageView.py +++ b/pyqtgraph/imageview/ImageView.py @@ -26,6 +26,7 @@ from ..graphicsItems.ROI import * from ..graphicsItems.LinearRegionItem import * from ..graphicsItems.InfiniteLine import * from ..graphicsItems.ViewBox import * +from ..graphicsItems.GradientEditorItem import addGradientListToDocstring from .. import ptime as ptime from .. import debug as debug from ..SignalProxy import SignalProxy @@ -717,4 +718,21 @@ class ImageView(QtGui.QWidget): if self.menu is None: self.buildMenu() self.menu.popup(QtGui.QCursor.pos()) - + + def setColorMap(self, colormap): + """Set the color map. + + ============= ========================================================= + **Arguments** + colormap (A ColorMap() instance) The ColorMap to use for coloring + images. + ============= ========================================================= + """ + self.ui.histogram.gradient.setColorMap(colormap) + + @addGradientListToDocstring() + def setPredefinedGradient(self, name): + """Set one of the gradients defined in :class:`GradientEditorItem `. + Currently available gradients are: + """ + self.ui.histogram.gradient.loadPreset(name)