设置子图 height/width
Set subplot height/width
我正在尝试创建一个包含一组子图的 window。子图必须具有不同的高度:
- 第 1 -- 50%
- 第二和第三 -- 各 25%
我正在玩 row
、col
、rowspan
和 colspan
参数,但没有运气。
所以,问题是:如何控制子图的大小(高度,宽度)(在创建时 or/and 创建后)?
Current heights
Heights needed
我当前的代码如下:
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_()
我找到了一些解决方案(也许不是最好的,但至少是有用的)。 layout
的 height
属性 可以与情节的 setFixedHeight
属性 一起使用。
用法示例:
indPlot.setFixedHeight(layout.height() * 0.25)
我正在尝试创建一个包含一组子图的 window。子图必须具有不同的高度:
- 第 1 -- 50%
- 第二和第三 -- 各 25%
我正在玩 row
、col
、rowspan
和 colspan
参数,但没有运气。
所以,问题是:如何控制子图的大小(高度,宽度)(在创建时 or/and 创建后)?
Current heights
Heights needed
我当前的代码如下:
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_()
我找到了一些解决方案(也许不是最好的,但至少是有用的)。 layout
的 height
属性 可以与情节的 setFixedHeight
属性 一起使用。
用法示例:
indPlot.setFixedHeight(layout.height() * 0.25)