1# -*- coding: utf-8 -*- 2""" 3This example demonstrates the ability to link the axes of views together 4Views can be linked manually using the context menu, but only if they are given 5names. 6""" 7 8import initExample ## Add path to library (just for examples; you do not need this) 9 10 11from pyqtgraph.Qt import QtGui, QtCore 12import numpy as np 13import pyqtgraph as pg 14 15app = pg.mkQApp("Linked Views Example") 16#mw = QtGui.QMainWindow() 17#mw.resize(800,800) 18 19x = np.linspace(-50, 50, 1000) 20y = np.sin(x) / x 21 22win = pg.GraphicsLayoutWidget(show=True, title="pyqtgraph example: Linked Views") 23win.resize(800,600) 24 25win.addLabel("Linked Views", colspan=2) 26win.nextRow() 27 28p1 = win.addPlot(x=x, y=y, name="Plot1", title="Plot1") 29p2 = win.addPlot(x=x, y=y, name="Plot2", title="Plot2: Y linked with Plot1") 30p2.setLabel('bottom', "Label to test offset") 31p2.setYLink('Plot1') ## test linking by name 32 33 34## create plots 3 and 4 out of order 35p4 = win.addPlot(x=x, y=y, name="Plot4", title="Plot4: X -> Plot3 (deferred), Y -> Plot1", row=2, col=1) 36p4.setXLink('Plot3') ## Plot3 has not been created yet, but this should still work anyway. 37p4.setYLink(p1) 38p3 = win.addPlot(x=x, y=y, name="Plot3", title="Plot3: X linked with Plot1", row=2, col=0) 39p3.setXLink(p1) 40p3.setLabel('left', "Label to test offset") 41#QtGui.QApplication.processEvents() 42 43if __name__ == '__main__': 44 pg.exec() 45 46