Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Benjamin Jakimow
EO Time Series Viewer
Commits
33b09dfa
Commit
33b09dfa
authored
Apr 03, 2012
by
Luke Campagnola
Browse files
Added crosshair example
parent
5a357ddb
Changes
1
Hide whitespace changes
Inline
Side-by-side
examples/crosshair.py
0 → 100644
View file @
33b09dfa
import
initExample
## Add path to library (just for examples; you do not need this)
import
numpy
as
np
import
pyqtgraph
as
pg
from
pyqtgraph.Qt
import
QtGui
,
QtCore
from
pyqtgraph.Point
import
Point
#genearte layout
app
=
QtGui
.
QApplication
([])
win
=
pg
.
GraphicsWindow
()
label
=
pg
.
LabelItem
(
justify
=
'right'
)
win
.
addItem
(
label
)
p1
=
win
.
addPlot
(
row
=
1
,
col
=
0
)
p2
=
win
.
addPlot
(
row
=
2
,
col
=
0
)
region
=
pg
.
LinearRegionItem
()
region
.
setZValue
(
10
)
p2
.
addItem
(
region
)
#create numpy arrays
#make the numbers large to show that the xrange shows data from 10000 to all the way 0
data1
=
10000
+
3000
*
np
.
random
.
random
(
size
=
10000
)
data2
=
15000
+
3000
*
np
.
random
.
random
(
size
=
10000
)
p1
.
plot
(
data1
,
pen
=
"r"
)
p1
.
plot
(
data2
,
pen
=
"g"
)
p2
.
plot
(
data1
,
pen
=
"w"
)
def
update
():
p1
.
setXRange
(
*
region
.
getRegion
())
region
.
sigRegionChanged
.
connect
(
update
)
region
.
setRegion
([
1000
,
2000
])
#cross hair
vLine
=
pg
.
InfiniteLine
(
angle
=
90
,
movable
=
False
)
hLine
=
pg
.
InfiniteLine
(
angle
=
0
,
movable
=
False
)
p1
.
addItem
(
vLine
,
ignoreBounds
=
True
)
p1
.
addItem
(
hLine
,
ignoreBounds
=
True
)
vb
=
p1
.
vb
def
mouseMoved
(
evt
):
pos
=
evt
[
0
]
## using signal proxy turns original arguments into a tuple
if
p1
.
sceneBoundingRect
().
contains
(
pos
):
mousePoint
=
vb
.
mapSceneToView
(
pos
)
index
=
int
(
mousePoint
.
x
())
if
index
>
0
and
index
<
len
(
data1
):
label
.
setText
(
"<span style='font-size: 12pt'>x=%0.1f, <span style='color: red'>y1=%0.1f</span>, <span style='color: green'>y2=%0.1f</span>"
%
(
mousePoint
.
x
(),
data1
[
index
],
data2
[
index
]))
vLine
.
setPos
(
mousePoint
.
x
())
hLine
.
setPos
(
mousePoint
.
y
())
proxy
=
pg
.
SignalProxy
(
p1
.
scene
().
sigMouseMoved
,
rateLimit
=
60
,
slot
=
mouseMoved
)
#p1.scene().sigMouseMoved.connect(mouseMoved)
## Start Qt event loop unless running in interactive mode or using pyside.
import
sys
if
(
sys
.
flags
.
interactive
!=
1
)
or
not
hasattr
(
QtCore
,
'PYQT_VERSION'
):
app
.
exec_
()
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment