pyqtgraph中子图的大小不相等

时间:2019-07-31 23:05:09

标签: python-2.7 pyqt pyqtgraph

我试图解决在pyqtgraph布局中为子图设置不同大小比例的问题,但没有成功。这是代码的样子

from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
import pyqtgraph.exporters
import numpy as np

app = QtGui.QApplication([])
view = pg.GraphicsView()
l = pg.GraphicsLayout(border=(100,100,100))
view.setCentralItem(l)
view.show()
view.setWindowTitle('pyqtgraph example: GraphicsLayout')
view.resize(1000,1600)

rows=range(3)
cols=range(3)
ar=0
for row in rows:
    ac=0
    for col in cols:
        l2=l.addLayout()
        p_res = l2.addPlot()
        p_res.hideAxis('bottom')
        l2.nextRow()
        p_data = l2.addPlot()
        p_res.plot([1,1,2,2,1,1])
        p_data.plot([1,3,2,4,3,5])
        ac=ac+1
        l.nextColumn()
    l.nextRow()
    ar=ar+1


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

exporter = pg.exporters.ImageExporter(view.scene())

# save to file
exporter.export('fileName.png')

此代码的输出如下:

6 panelled plot

在这里我们看到3行3列的9个图。考虑到第1行和第1列的图,如何将顶部面板中的子图尺寸与下方面板中的子图尺寸比例更改为1:3?

1 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,进行了很好的讨论,并在https://groups.google.com/forum/#!topic/pyqtgraph/aMaCMOrrrJghttps://groups.google.com/forum/#!topic/pyqtgraph/RJjtJea9KFc处进行了修复

我的代码是

AudioWorkletNode