Absolute colormaps

35 views
Skip to first unread message

Alessandro Tontini

unread,
Dec 10, 2018, 11:09:23 AM12/10/18
to pyqtgraph
Hi all,

I am struggling to find a way to obtain absolute colormaps with pyqtgraph. The code snippet below is what I am using to define my colormap:


c_pos = np.array([31*0.0, 31*0.25, 31*0.75, 31*1.0])
c_color
= np.array([[0, 0, 0, 255], [255, 0, 0, 255], [255, 255, 0, 255], [255, 255, 255, 255]], dtype=np.ubyte)
c_map
= pg.ColorMap(c_pos, c_color)
self.c_lut = c_map.getLookupTable(0.0, 31*1.0, 31)

My input data are integers ranging from 0 up to 31.

What I am trying to obtain is a uniform colormap with 0=black and 31=white, with shades from red to yellow in the middle.

The problem is that, if my input values are for example from 0 to 15 (instead from 0 to 31), pyqtgraph makes the resulting colormap "relative", i.e. I have black for 0 up to white for 15.

Is there any way to define an absolute color map?

Thank you in advance

Patrick

unread,
Dec 10, 2018, 9:03:54 PM12/10/18
to pyqtgraph
Hi,

It looks like your colormap would be working fine (except shouldn't you be requesting 32 points not 31 in getLookupTable?). Do you mean when you display image data using that colormap, then the range is scaled to the minimum/maximum of the image data? If that's the case then there are options for ImageItem/setImage to control that (http://www.pyqtgraph.org/documentation/graphicsItems/imageitem.html#pyqtgraph.ImageItem.setImage). Try passing in "lut=self.c_lut, levels=(0, 31)" options.

Patrick

Alessandro Tontini

unread,
Dec 14, 2018, 2:41:53 AM12/14/18
to pyqtgraph
Again, that did the job. Thank you!
Reply all
Reply to author
Forward
0 new messages