假设我在 pyqtgraph 中创建了两个视图\绘图,然后将它们链接起来。使用线条
p2.setYLink('Plot1')
p2.setXLink('Plot1')
问题是,当我们链接视图时,两个视图的范围是相等的,这会引发问题,因为一个图似乎被缩小或放大了太多。我们只想链接视图以放大但不希望范围随着情节的变化而变化。
以下是直观地解释问题的示例代码
import sys
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
import pyqtgraph as pg
#QtGui.QApplication.setGraphicsSystem('raster')
try:
app = QtGui.QApplication(sys.argv)
except RuntimeError:
app = QtCore.QCoreApplication.instance()
x1 = [1,2,3,4,5]
y1 = x1
x2 = [10,20,30,40,50]
y2 = x2
win = pg.GraphicsWindow(title="pyqtgraph example: Linked Views")
win.resize(800,600)
win.addLabel("Linked Views", colspan=2)
win.nextRow()
p1 = win.addPlot(x=x1, y=y1, name="Plot1", title="Plot1")
p2 = win.addPlot(x=x2, y=y2, name="Plot2", title="Plot2: Y linked with Plot1")
p2_state = p2.vb.getState()
p1_state = p1.vb.getState()
p2.setLabel('bottom', "Label to test offset")
p2.setYLink('Plot1') ## test linking by name
p2.setXLink('Plot1')
app.exec_()