1# -*- coding: utf-8 -*-
2"""
3Simple example of GraphItem use.
4"""
5
6
7import initExample ## Add path to library (just for examples; you do not need this)
8
9import pyqtgraph as pg
10from pyqtgraph.Qt import QtCore, QtGui
11import numpy as np
12
13# Enable antialiasing for prettier plots
14pg.setConfigOptions(antialias=True)
15
16w = pg.GraphicsLayoutWidget(show=True)
17w.setWindowTitle('pyqtgraph example: GraphItem')
18v = w.addViewBox()
19v.setAspectLocked()
20
21g = pg.GraphItem()
22v.addItem(g)
23
24## Define positions of nodes
25pos = np.array([
26    [0,0],
27    [10,0],
28    [0,10],
29    [10,10],
30    [5,5],
31    [15,5]
32    ])
33
34## Define the set of connections in the graph
35adj = np.array([
36    [0,1],
37    [1,3],
38    [3,2],
39    [2,0],
40    [1,5],
41    [3,5],
42    ])
43
44## Define the symbol to use for each node (this is optional)
45symbols = ['o','o','o','o','t','+']
46
47## Define the line style for each connection (this is optional)
48lines = np.array([
49    (255,0,0,255,1),
50    (255,0,255,255,2),
51    (255,0,255,255,3),
52    (255,255,0,255,2),
53    (255,0,0,255,1),
54    (255,255,255,255,4),
55    ], dtype=[('red',np.ubyte),('green',np.ubyte),('blue',np.ubyte),('alpha',np.ubyte),('width',float)])
56
57## Update the graph
58g.setData(pos=pos, adj=adj, pen=lines, size=1, symbol=symbols, pxMode=False)
59
60if __name__ == '__main__':
61    pg.exec()
62