2011-04-05 16:53:05 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2013-02-25 04:09:03 +00:00
|
|
|
"""
|
|
|
|
Display an animated arrowhead following a curve.
|
|
|
|
This example uses the CurveArrow class, which is a combination
|
2014-02-01 04:00:18 +00:00
|
|
|
of ArrowItem and CurvePoint.
|
2012-03-17 15:47:20 +00:00
|
|
|
|
2013-02-25 04:09:03 +00:00
|
|
|
To place a static arrow anywhere in a scene, use ArrowItem.
|
|
|
|
To attach other types of item to a curve, use CurvePoint.
|
|
|
|
"""
|
2012-03-17 15:47:20 +00:00
|
|
|
|
|
|
|
import initExample ## Add path to library (just for examples; you do not need this)
|
2011-04-05 16:53:05 +00:00
|
|
|
|
|
|
|
import numpy as np
|
2012-03-02 03:53:52 +00:00
|
|
|
from pyqtgraph.Qt import QtGui, QtCore
|
2011-04-05 16:53:05 +00:00
|
|
|
import pyqtgraph as pg
|
|
|
|
|
|
|
|
|
2021-01-27 18:42:38 +00:00
|
|
|
app = QtGui.QApplication([])
|
2011-04-05 16:53:05 +00:00
|
|
|
|
2012-05-30 03:44:14 +00:00
|
|
|
w = QtGui.QMainWindow()
|
|
|
|
cw = pg.GraphicsLayoutWidget()
|
|
|
|
w.show()
|
|
|
|
w.resize(400,600)
|
|
|
|
w.setCentralWidget(cw)
|
2013-02-25 04:09:03 +00:00
|
|
|
w.setWindowTitle('pyqtgraph example: Arrow')
|
2012-05-30 03:44:14 +00:00
|
|
|
|
|
|
|
p = cw.addPlot(row=0, col=0)
|
|
|
|
p2 = cw.addPlot(row=1, col=0)
|
|
|
|
|
|
|
|
## variety of arrow shapes
|
|
|
|
a1 = pg.ArrowItem(angle=-160, tipAngle=60, headLen=40, tailLen=40, tailWidth=20, pen={'color': 'w', 'width': 3})
|
|
|
|
a2 = pg.ArrowItem(angle=-120, tipAngle=30, baseAngle=20, headLen=40, tailLen=40, tailWidth=8, pen=None, brush='y')
|
2020-06-10 05:04:29 +00:00
|
|
|
a3 = pg.ArrowItem(angle=-60, baseAngle=20, headLen=40, headWidth=20, tailLen=None, brush=None)
|
2012-05-30 03:44:14 +00:00
|
|
|
a4 = pg.ArrowItem(angle=-20, tipAngle=30, baseAngle=-30, headLen=40, tailLen=None)
|
|
|
|
a2.setPos(10,0)
|
|
|
|
a3.setPos(20,0)
|
|
|
|
a4.setPos(30,0)
|
|
|
|
p.addItem(a1)
|
|
|
|
p.addItem(a2)
|
|
|
|
p.addItem(a3)
|
|
|
|
p.addItem(a4)
|
|
|
|
p.setRange(QtCore.QRectF(-20, -10, 60, 20))
|
|
|
|
|
|
|
|
|
|
|
|
## Animated arrow following curve
|
|
|
|
c = p2.plot(x=np.sin(np.linspace(0, 2*np.pi, 1000)), y=np.cos(np.linspace(0, 6*np.pi, 1000)))
|
2011-04-05 16:53:05 +00:00
|
|
|
a = pg.CurveArrow(c)
|
2014-02-01 04:00:18 +00:00
|
|
|
a.setStyle(headLen=40)
|
2012-05-30 03:44:14 +00:00
|
|
|
p2.addItem(a)
|
2011-04-05 16:53:05 +00:00
|
|
|
anim = a.makeAnimation(loop=-1)
|
|
|
|
anim.start()
|
|
|
|
|
2012-03-17 15:47:20 +00:00
|
|
|
## Start Qt event loop unless running in interactive mode or using pyside.
|
2012-12-05 05:25:45 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
|
|
|
|
QtGui.QApplication.instance().exec_()
|