Legen Diary
Legen Diary

Reputation: 365

pyqtgraph changing limits on displayed color scale using pyqtgraph.image()

I'm trying to change the scale of the data being displayed (not sure if this is what it is called) I want to change the range circled in red to be 3-6 as the default when it launches

look for the red

Everything I've read suggests it should be as simple as grabbing the ImageView object and calling setLevels() as shown here. The problem is that I can't find the ImageView object found within an ImageWindow.

Here's my initial code

imv = pg.image(amps)
okay = imv.imageItem

imv.view.setAspectLocked(ratio = 4)
print( vars(imv))
imv.setLimits(3,6)

win = QtGui.QMainWindow()

#im.setLookupTable(lut)
if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):            
        QtGui.QApplication.instance().exec_()

but it says that ImageWindow has no attribute setLimits.

I tried searching for the ImageView by running

print(vars(imv))

but the closest thing I could find is the ImageItem but

imv.imageItem.setLevels(3,6)

raises the error of "levels argument must be 1d or 2d". This makes me think this is not the right path.

Thanks for your help

EDIT:

I tried

imv.imageItem.setLevels((3,6))

which produces the following

new picture

The range is correct on the data, but the legend on the right is not updated correctly

Upvotes: 1

Views: 3625

Answers (1)

Luke
Luke

Reputation: 11644

ImageWindow is a subclass of ImageView, so all the same methods should apply. Documentation is here: http://www.pyqtgraph.org/documentation/widgets/imageview.html#pyqtgraph.ImageView.setImage

These are all different ways of writing approximately the same thing:

# 1:
pg.image(data, levels=[3, 6])

# 2:
imv = pg.image(data)
imv.setLevels(3, 6)

# 3:
imv = pg.ImageView()
imv.setImage(data, levels=[3, 6])    

Upvotes: 2

Related Questions