I have a set of scalar values for a scatter plot and I'd like to visualize 
them using a blue-red colormap i.e. the higher the value, the redder the 
SpotItem is. I googled around and I came across a relevant implementation 
here <http://amyboyle.ninja/Pyqtgraph-live-spectrogram> but it's for an 
ImageItem (I'm working with a PlotWidget). I learned that the colors are 
determined by a ColorMap e.g.

pos = np.array([0., 1., 0.5, 0.25, 0.75])
color = np.array([[0,255,255,255], [255,255,0,255], [0,0,0,255], (0, 0, 255, 
255), (255, 0, 0, 255)], dtype=np.ubyte)
cmap = pg.ColorMap(pos, color)
lut = cmap.getLookupTable(0.0, 1.0, 256)

self.img.setLookupTable(lut)
self.img.setLevels([-50,40])


On the ColorMap 
<http://www.pyqtgraph.org/documentation/colormap.html?highlight=colormap>API 
page there's map(*data*, *mode='byte'*) so to quickly test it out I copied 
the ColorMap code from the ImageView example:

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)

for pin in self.item_map:    
    item_value = random.randint(1, 100)
    color = cmap.mapToQColor(item_value)


    item = self.item_map[pin]

# item.setBrush(color)

print(color.name())


Something is wrong with my implementation because all colors returned from 
mapToQColor are the same.and I am not sure what i'm missing.

Extra question: I have 2000+ SpotItems on my PlotWidget and setting the 
brush for all 2000+ items hangs the app for few minutes. What can I do to 
optimize the brush setting process besides switching to an ImageView?

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/7bb8902b-0a86-48ec-baf0-87eed79b5be0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to