a b/Inference/test.py
1
# -*- coding: utf-8 -*-
2
"""
3
This example shows how to insert text into a scene using TextItem. This class 
4
is for displaying text that is anchored to a particular location in the data
5
coordinate system, but which is always displayed unscaled. 
6
7
For text that scales with the data, use QTextItem. 
8
For text that can be placed in a layout, use LabelItem.
9
"""
10
11
 ## Add path to library (just for examples; you do not need this)
12
13
import pyqtgraph as pg
14
from pyqtgraph.Qt import QtCore, QtGui
15
import numpy as np
16
17
18
x = np.linspace(-20, 20, 1000)
19
y = np.sin(x) / x
20
plot = pg.plot()   ## create an empty plot widget
21
plot.setYRange(-1, 2)
22
plot.setWindowTitle('pyqtgraph example: text')
23
curve = plot.plot(x,y)  ## add a single curve
24
25
## Create text object, use HTML tags to specify color/size
26
text = pg.TextItem(html='<div style="text-align: center"><span style="color: #FFF;">This is the</span><br><span style="color: #FF0; font-size: 16pt;">PEAK</span></div>', anchor=(-0.3,0.5), angle=45, border='w', fill=(0, 0, 255, 100))
27
plot.addItem(text)
28
text.setPos(0, y.max())
29
30
## Draw an arrowhead next to the text box
31
arrow = pg.ArrowItem(pos=(0, y.max()), angle=-45)
32
plot.addItem(arrow)
33
34
35
## Set up an animated arrow and text that track the curve
36
curvePoint = pg.CurvePoint(curve)
37
plot.addItem(curvePoint)
38
text2 = pg.TextItem("test", anchor=(0.5, -1.0))
39
text2.setParentItem(curvePoint)
40
arrow2 = pg.ArrowItem(angle=90)
41
arrow2.setParentItem(curvePoint)
42
43
## update position every 10ms
44
index = 0
45
def update():
46
    global curvePoint, index
47
    index = (index + 1) % len(x)
48
    print(float(index)/(len(x)-1))
49
    curvePoint.setPos(float(index)/(len(x)-1))
50
    text2.setText('[%0.1f, %0.1f]' % (x[index], y[index]))
51
    
52
timer = QtCore.QTimer()
53
timer.timeout.connect(update)
54
timer.start(10)
55
56
57
58
## Start Qt event loop unless running in interactive mode or using pyside.
59
if __name__ == '__main__':
60
    import sys
61
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
62
        QtGui.QApplication.instance().exec_()