Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set logarithmic scale and axis limits in HistogramLUTItem in pyqtgraph

Tags:

pyqtgraph

I'm using pyqtgraph for a live view of a camera acquisition program. Most of the times my images are composed of a lot of background noise and a signal of just a few pixels with higher intensity. For that reason, the part of the HistogramLUTItem that corresponds to the actual signal looks like a thin line and the noise is big next to it. Being able to plot the logarithm of the data would make the data to stand up more.

Is this possible?

I'm currently creating the histogram this way:

    imagewidget = pg.GraphicsLayoutWidget()
    self.p1 = imagewidget.addPlot()
    self.img = pg.ImageItem()
    self.p1.addItem(self.img)
    self.p1.getViewBox().setAspectLocked(True)
    self.hist = pg.HistogramLUTItem()
    self.hist.setImageItem(self.img)
    self.hist.autoHistogramRange = False
    imagewidget.addItem(self.hist)

Doing self.hist.axis.setLogMode(True) didn't work as it affected the x-axis of the histogram instead of the y-axis.

And finally, I would also like to be able to limit the accesible range in the x-axis of the histogram. How can this be done?

Cheers!

like image 991
Federico Barabas Avatar asked Mar 18 '23 20:03

Federico Barabas


1 Answers

Ok, I finally figured out. In case someone wonders, I solved it by adding these two lines:

self.hist.plot.setLogMode(False, True)
self.hist.vb.setLimits(yMin=0, yMax=16000)
like image 126
Federico Barabas Avatar answered Apr 30 '23 22:04

Federico Barabas