我试图解决在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')
此代码的输出如下:
这里我们看到3行3列的9个图。考虑到第1行和第1列的图,如何将顶图中的子图尺寸与下图中的子图尺寸之比更改为1:3?]
我遇到了同样的问题,进行了很好的讨论,并在https://groups.google.com/forum/#!topic/pyqtgraph/aMaCMOrrrJg或https://groups.google.com/forum/#!topic/pyqtgraph/RJjtJea9KFc中修复
我的代码是
self.graphics_layout_widget = pg.GraphicsLayoutWidget() # contains a graphicsview
self.plot_holding_grid.addWidget(self.graphics_layout_widget, 0, 0, 1, 1)
self.graphics_layout_widget.setBackground('w')
upperplot = self.graphics_layout_widget.addPlot(0, 0, 1, 1)
plotpen = pg.mkPen(color='k', width=2)
upperplot.plot(first_time, first_record, pen=plotpen)
lowerplot = self.graphics_layout_widget.addPlot(1, 0, 1, 1)
# restrict size of plot areas
self.graphics_layout_widget.ci.layout.setRowStretchFactor(0, 4)
self.graphics_layout_widget.ci.layout.setRowStretchFactor(1, 1)