2013-01-30 20:56:08 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
2013-02-25 04:09:03 +00:00
|
|
|
Simple example of GraphItem use.
|
2013-01-30 20:56:08 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
import initExample ## Add path to library (just for examples; you do not need this)
|
|
|
|
|
|
|
|
import pyqtgraph as pg
|
|
|
|
from pyqtgraph.Qt import QtCore, QtGui
|
|
|
|
import numpy as np
|
|
|
|
|
2013-03-26 17:46:26 +00:00
|
|
|
# Enable antialiasing for prettier plots
|
|
|
|
pg.setConfigOptions(antialias=True)
|
|
|
|
|
2013-01-30 20:56:08 +00:00
|
|
|
w = pg.GraphicsWindow()
|
2013-02-25 04:09:03 +00:00
|
|
|
w.setWindowTitle('pyqtgraph example: GraphItem')
|
2013-01-30 20:56:08 +00:00
|
|
|
v = w.addViewBox()
|
|
|
|
v.setAspectLocked()
|
|
|
|
|
|
|
|
g = pg.GraphItem()
|
|
|
|
v.addItem(g)
|
|
|
|
|
|
|
|
## Define positions of nodes
|
|
|
|
pos = np.array([
|
|
|
|
[0,0],
|
|
|
|
[10,0],
|
|
|
|
[0,10],
|
|
|
|
[10,10],
|
|
|
|
[5,5],
|
|
|
|
[15,5]
|
|
|
|
])
|
|
|
|
|
|
|
|
## Define the set of connections in the graph
|
|
|
|
adj = np.array([
|
|
|
|
[0,1],
|
|
|
|
[1,3],
|
|
|
|
[3,2],
|
|
|
|
[2,0],
|
|
|
|
[1,5],
|
|
|
|
[3,5],
|
|
|
|
])
|
|
|
|
|
|
|
|
## Define the symbol to use for each node (this is optional)
|
|
|
|
symbols = ['o','o','o','o','t','+']
|
|
|
|
|
|
|
|
## Define the line style for each connection (this is optional)
|
|
|
|
lines = np.array([
|
|
|
|
(255,0,0,255,1),
|
|
|
|
(255,0,255,255,2),
|
|
|
|
(255,0,255,255,3),
|
|
|
|
(255,255,0,255,2),
|
|
|
|
(255,0,0,255,1),
|
|
|
|
(255,255,255,255,4),
|
|
|
|
], dtype=[('red',np.ubyte),('green',np.ubyte),('blue',np.ubyte),('alpha',np.ubyte),('width',float)])
|
|
|
|
|
|
|
|
## Update the graph
|
|
|
|
g.setData(pos=pos, adj=adj, pen=lines, size=1, symbol=symbols, pxMode=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Start Qt event loop unless running in interactive mode or using pyside.
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
|
|
|
|
QtGui.QApplication.instance().exec_()
|