在 pyqtgraph 中将图像拉伸到 window 大小

Strech image to window size in pyqtgraph

我目前正在尝试创建一个 PyQtGraph gui,以便在新数据传入时使用类似于以下的代码重复绘制图像:

self.app = QtGui.QApplication([])
self.win = QtGui.QMainWindow()
self.win.resize(800, 600)
self.imv = pg.ImageView()
self.win.setCentralWidget(self.imv)
self.win.setWindowTitle('My Title')
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.check_for_new_data_and_replot)
self.timer.start(100)
self.win.show()

然后每次获得新数据时我都会绘制图像:

self.imv.setImage(self.data_array)

我 运行 遇到的一个问题是我的数据数组通常有一个倾斜的纵横比,即它通常实际上是 "tall and skinny" 或 "short and fat",而图像是绘制的具有相同的比例。

有没有办法拉伸图像以适应 window?我已查看 ImageView and ImageItem 的文档,但找不到我需要的内容。 (也许它在那里,但我无法识别它。)

我想通了——使用较低级别的 ImageItem class 以拉伸以适合 window 大小的方式显示图像:

self.app = QtGui.QApplication([])
self.win = pg.GraphicsLayoutWidget()
self.win.resize(800, 600)
self.img = pg.ImageItem()
self.plot = self.win.addPlot()
self.plot.addItem(self.img)
self.win.setWindowTitle('My Title')
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.check_for_new_data_and_replot)
self.timer.start(100)
self.win.show()

并更新图像数据:

self.img.setImage(self.data_array)

这也让我可以在侧面显示轴刻度,这也是我想要的功能。