在 pyqtgraph 中导出小部件的图像

Exporting Image of the widget in pyqtgraph

我正在创建一个 GraphicsLayoutWidget,然后使用 addPlot() 向小部件添加图表。此小部件不显示在屏幕上,但用于导出图像,使用:

    exporter = pyqtgraph.exporters.ImageExporter(pwidget.scene())
    exporter.export(os.path.join(datadirtemp, str(typename) + '.png'))

但是图片从来没有涵盖整个情节。

此外,使用以下项目也无济于事:

exporter.parameters()['width'] = pwidget.scene().sceneRect().width()

我收到以下错误:

Cannot export image with size=0 (requested export size is 0x0)

您正试图在 window 初始化之前将其导出。所以你需要做

QtGui.QApplication.processEvents()

在导出之前。

参考link: from pyqtgraph's forum