import numpy as np
import matplotlib.pyplot as mpl
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph as pg
app = QtGui.QApplication([])
## Create window with two ImageView widgets
win = QtGui.QMainWindow()
win.resize(1000, 1000)
win.setWindowTitle('Triple Correlations')
cw = QtGui.QWidget()
win.setCentralWidget(cw)
l = QtGui.QGridLayout()
cw.setLayout(l)
imv1 = pg.ImageView()
imv2 = pg.ImageView()
l.addWidget(imv1, 0, 0)
l.addWidget(imv2, 1, 0)
win.show()
## Set your 3D data to be displayed here
data = np.random.random(3*(100,))
roi = pg.LineSegmentROI([[10, len(data)//2], [len(data)-10, len(data)//2]], pen='r')
imv1.addItem(roi)
def update():
global data, imv1, imv2
d2 = roi.getArrayRegion(data, imv1.imageItem, axes=(1, 2))
imv2.setImage(d2)
roi.sigRegionChanged.connect(update)
## Display the data
imv1.setImage(data)
imv1.setHistogramRange(0, 2)
imv1.setLevels(0, 2)
update()
## Start Qt event loop unless running in interactive mode.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
Visualizing 3D Data Cubes with PyQtGraph
PyQtGraph has some useful tools for visualizing 3D data. I'm copying below a simple example for my own future reference.