【问题标题】:Strech image to window size in pyqtgraph在pyqtgraph中将图像拉伸到窗口大小
【发布时间】:2015-09-13 17:36:13
【问题描述】:

我目前正在尝试创建一个 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)

我遇到的一个问题是我的数据数组通常具有倾斜的纵横比,即它通常真的是“又高又瘦”或“又短又胖”,并且绘制的图像具有相同的比例。

有没有办法拉伸图像以适应窗口?我查看了ImageViewImageItem 的文档,但找不到我需要的东西。 (也许它在那里,但我无法识别它。)

【问题讨论】:

  • 试试ImageView::setImage()transform 选项。类似transform = QTransform().scale(sx, sy)

标签: qt pyqt4 pyqtgraph


【解决方案1】:

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

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)

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-14
    • 1970-01-01
    • 2020-11-21
    • 1970-01-01
    • 1970-01-01
    • 2010-09-19
    相关资源
    最近更新 更多