How to change colors of img item that is bound to LUT item ?

250 views
Skip to first unread message

Luka Drmic

unread,
Aug 6, 2018, 8:52:29 AM8/6/18
to pyqtgraph

central_item = pg.GraphicsLayout()
main_subplot
= central_item.addPlot()
img
= pg.ImageItem()
img
.setImage(self.plt_data)
main_subplot
.addItem(img)

histogram
= pg.HistogramLUTItem()
histogram
.setImageItem(img)
histogram
.setFixedWidth(128)

How do i make the colors default to one of the options in the right click menu of the GradientEditorItem instead of the black-white option.

Or in other words, how do i programmatically change the colors of my image.



Desired result:


Patrick

unread,
Aug 7, 2018, 1:26:27 AM8/7/18
to pyqtgraph
Hi,

You can access the GradientEditorItem (http://www.pyqtgraph.org/documentation/graphicsItems/gradienteditoritem.html) component directly and set one of the default colormaps by:

histogram.gradient.loadPreset('thermal')

You can also make your own custom gradient with something like:
histogram.gradient.restoreState({"mode": "rgb",
            "ticks": [(0.00, (0, 0, 0)),
                      (0.05, (0, 0, 128)),
                      (0.50, (185, 0 , 0)),
                      (0.75, (255, 220, 0)),
                      (1.00, (255, 255, 255))]})


Patrick

Luka Drmic

unread,
Aug 8, 2018, 4:32:18 AM8/8/18
to pyqt...@googlegroups.com
Thank you kind sir.

--
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 pyqtgraph+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/ddb0cf87-8665-4a0d-809e-ea242de5d469%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages