【发布时间】:2020-11-08 17:32:47
【问题描述】:
我正在尝试创建一个包含一组子图的窗口。子图的高度必须不同:
- 1st -- 50%
- 第二和第三 -- 各 25%
我正在使用 row、col、rowspan 和 colspan 参数,但没有运气。
所以,问题是:如何控制子图的大小(高度、宽度)(在创建时或/和创建后)?
我当前的代码如下:
import PyQt5
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
from random import randint as ri
def BarChart(x):
global layout
barPlot = layout.addPlot(row=0, col=0, rowspan=2, colspan=1)
barPlot.showGrid(x=True, y=True, alpha=0.5)
barPlot.plot(x)
ax = barPlot.getAxis('bottom')
ax.setStyle(showValues=False)
return barPlot
def IndChart(x, barPlot):
global layout
indPlot = layout.addPlot(row=2, col=0, rowspan=1, colspan=1)
indPlot.showGrid(x=True, y=True, alpha=0.5)
indPlot.plot(x)
indPlot.setXLink(barPlot)
ax = indPlot.getAxis('bottom')
ax.setStyle(showValues=False)
return indPlot
def IndChart2(x, barPlot):
global layout
indPlot = layout.addPlot(row=3, col=0, rowspan=1, colspan=1)
indPlot.showGrid(x=True, y=True, alpha=0.5)
indPlot.plot(x)
indPlot.setXLink(barPlot)
return indPlot
if __name__ == '__main__':
app = QtGui.QApplication([])
view = pg.GraphicsView()
layout = pg.GraphicsLayout()
layout.layout.setSpacing(0)
layout.setContentsMargins(0, 0, 0, 0)
view.setCentralItem(layout)
view.show()
x = [0] + [ri(0, 100) for i in range(100)] + [100]
barPlot = BarChart(x)
indPlot = IndChart(x, barPlot)
indPlot2 = IndChart2(x, barPlot)
x = [0] + [ri(0, 100) for i in range(100)] + [100]
barPlot.plot(x, pen=(255, 0, 0))
app.exec_()
【问题讨论】: