Use the slider for time (custom ROI?)

303 views
Skip to first unread message

Simon Hafner

unread,
Dec 2, 2013, 1:43:39 PM12/2/13
to pyqt...@googlegroups.com
Hello

I mentioned drawing lines in the other thread, each of those lines describes an event occurring at a specific time. The data slice example mentions a LineSegmentROI, but nothing about a slider. In the examples, I don't see any code generating the sliders, so I assume it works via some additional axis, like in the ImageView. The custom ROI examples are only for in-image selection.

Cheers

Luke Campagnola

unread,
Dec 2, 2013, 5:07:06 PM12/2/13
to pyqt...@googlegroups.com
On Mon, Dec 2, 2013 at 1:43 PM, Simon Hafner <react...@gmail.com> wrote:
I mentioned drawing lines in the other thread, each of those lines describes an event occurring at a specific time. The data slice example mentions a LineSegmentROI, but nothing about a slider. In the examples, I don't see any code generating the sliders, so I assume it works via some additional axis, like in the ImageView. The custom ROI examples are only for in-image selection.

I'm not sure what your question is, but perhaps pg.InfiniteLine or pg.LinearRegionItem provide what you need? Or possibly QtGui.QSlider ?
 

Simon Hafner

unread,
Dec 2, 2013, 6:39:59 PM12/2/13
to pyqt...@googlegroups.com
No, to what I read they don't fit. I want to draw lines, which indicate actions. Each of those lines happens at a specific point in time. I want to the slider so I can say "display all lines between 10 min and 30min" or "all from 5 to 8min".

Luke Campagnola

unread,
Dec 2, 2013, 7:12:30 PM12/2/13
to pyqt...@googlegroups.com
If I understand your purpose, then all three suggestions should work for you. Example:

import pyqtgraph as pg
import numpy as np
pg.mkQApp()
w = pg.GraphicsLayoutWidget()

p1 = w.addPlot()
p2 = w.addPlot(row=1, col=0)
p2.hideAxis('left')
p2.setXRange(0, 10)
p2.vb.setMouseEnabled(False, False)
w.ci.layout.setRowFixedHeight(1, 50)
w.show()

lr = pg.LinearRegionItem([0, 10])
p2.addItem(lr, ignoreBounds=True)

N = 10000
data = np.random.normal(size=(N*2, 2))
data[1::2] = data[::2] + np.random.normal(size=(N,2), scale=0.1)

connect = np.ones(N*2, dtype=np.uint32)
connect[1::2] = 0
curve = pg.PlotCurveItem(x=data[:,0], y=data[:,1], connect=connect)
p1.addItem(curve)

times = np.linspace(0, 10, N)

def update():
    global data, curve, times, lr
    connect = np.ones(N*2, dtype=np.uint32)
    connect[1::2] = 0
    start, stop = lr.getRegion()
    connect[::2][times < start] = 0
    connect[::2][times > stop] = 0
    curve.setData(x=data[:,0], y=data[:,1], connect=connect)

lr.sigRegionChanged.connect(update)
update()


 

Simon Hafner

unread,
Dec 2, 2013, 7:53:04 PM12/2/13
to pyqt...@googlegroups.com
That code segfaults here.

python version 2.7.6, pyqtgraph 0.9.7, qt 4.8.5, Archlinux. 

#0  0x00007ffff51b0154 in QObject::thread() const () from /usr/lib/libQtCore.so.4
#1  0x00007ffff65b62bf in ?? () from /usr/lib/python2.7/site-packages/PyQt4/QtGui.so
#2  0x00007ffff1c1e9e6 in ?? () from /usr/lib/python2.7/site-packages/sip.so
#3  0x00007ffff1c1fbf9 in ?? () from /usr/lib/python2.7/site-packages/sip.so
#4  0x00007ffff7ab51c3 in subtype_dealloc () from /usr/lib/libpython2.7.so.1.0
#5  0x00007ffff7a99cdf in dict_dealloc () from /usr/lib/libpython2.7.so.1.0
#6  0x00007ffff1c1c0e7 in ?? () from /usr/lib/python2.7/site-packages/sip.so
#7  0x00007ffff1c1fb54 in ?? () from /usr/lib/python2.7/site-packages/sip.so
#8  0x00007ffff1c1fc01 in ?? () from /usr/lib/python2.7/site-packages/sip.so
#9  0x00007ffff7ab51c3 in subtype_dealloc () from /usr/lib/libpython2.7.so.1.0
#10 0x00007ffff1c1fb75 in ?? () from /usr/lib/python2.7/site-packages/sip.so
#11 0x00007ffff1c1fc01 in ?? () from /usr/lib/python2.7/site-packages/sip.so
#12 0x00007ffff7ab51c3 in subtype_dealloc () from /usr/lib/libpython2.7.so.1.0
#13 0x00007ffff1c1fb75 in ?? () from /usr/lib/python2.7/site-packages/sip.so
#14 0x00007ffff1c1fc01 in ?? () from /usr/lib/python2.7/site-packages/sip.so
#15 0x00007ffff7ab51c3 in subtype_dealloc () from /usr/lib/libpython2.7.so.1.0
#16 0x00007ffff1c1fb75 in ?? () from /usr/lib/python2.7/site-packages/sip.so
#17 0x00007ffff1c1fc01 in ?? () from /usr/lib/python2.7/site-packages/sip.so
#18 0x00007ffff7ab51c3 in subtype_dealloc () from /usr/lib/libpython2.7.so.1.0
#19 0x00007ffff7a99cdf in dict_dealloc () from /usr/lib/libpython2.7.so.1.0
#20 0x00007ffff1c1c107 in ?? () from /usr/lib/python2.7/site-packages/sip.so
#21 0x00007ffff1c1fb54 in ?? () from /usr/lib/python2.7/site-packages/sip.so
#22 0x00007ffff1c1fc01 in ?? () from /usr/lib/python2.7/site-packages/sip.so
#23 0x00007ffff7ab51c3 in subtype_dealloc () from /usr/lib/libpython2.7.so.1.0
#24 0x00007ffff7a98e4f in insertdict_by_entry () from /usr/lib/libpython2.7.so.1.0
#25 0x00007ffff7a9a7b0 in dict_set_item_by_hash_or_entry () from /usr/lib/libpython2.7.so.1.0
#26 0x00007ffff7a9ef6c in _PyModule_Clear () from /usr/lib/libpython2.7.so.1.0
#27 0x00007ffff7b0989d in PyImport_Cleanup () from /usr/lib/libpython2.7.so.1.0
#28 0x00007ffff7b14b6e in Py_Finalize () from /usr/lib/libpython2.7.so.1.0
#29 0x00007ffff7b256d5 in Py_Main () from /usr/lib/libpython2.7.so.1.0
#30 0x00007ffff7474bc5 in __libc_start_main () from /usr/lib/libc.so.6
#31 0x0000000000400741 in _start ()

 

Luke Campagnola

unread,
Dec 2, 2013, 8:05:07 PM12/2/13
to pyqt...@googlegroups.com
Sorry, either run it from a python interactive prompt or add `pg.QtGui.QApplication.exec_()` to the end.
 

Simon Hafner

unread,
Dec 2, 2013, 8:53:42 PM12/2/13
to pyqt...@googlegroups.com
Am Montag, 2. Dezember 2013 19:05:07 UTC-6 schrieb Luke Campagnola:
Sorry, either run it from a python interactive prompt or add `pg.QtGui.QApplication.exec_()` to the end.
Thanks.

I played around with the slider, but the data displayed does not seem to change. I see how this should work, but apparently it doesn't that well. It mentions to use arrays of boolean values, are 0/1 fine there?

Simon Hafner

unread,
Dec 2, 2013, 9:20:06 PM12/2/13
to pyqt...@googlegroups.com
The connect doesn't seem to work at all, when I set it to "pairs" there are still connected lines. 

Simon Hafner

unread,
Dec 2, 2013, 9:22:55 PM12/2/13
to pyqt...@googlegroups.com
Am Montag, 2. Dezember 2013 20:20:06 UTC-6 schrieb Simon Hafner:
Am Montag, 2. Dezember 2013 19:53:42 UTC-6 schrieb Simon Hafner:
Am Montag, 2. Dezember 2013 19:05:07 UTC-6 schrieb Luke Campagnola:0
Sorry, either run it from a python interactive prompt or add `pg.QtGui.QApplication.exec_()` to the end.
Thanks.

I played around with the slider, but the data displayed does not seem to change. I see how this should work, but apparently it doesn't that well. It mentions to use arrays of boolean values, are 0/1 fine there?
The connect doesn't seem to work at all, when I set it to "pairs" there are still connected lines. 
Solved by updating to 0.9.8. 

Simon Hafner

unread,
Dec 2, 2013, 9:30:27 PM12/2/13
to pyqt...@googlegroups.com
In the Slider, how do I display the graph like in ImageView? 

Luke Campagnola

unread,
Dec 2, 2013, 11:01:08 PM12/2/13
to pyqt...@googlegroups.com
Call p2.plot(x, y) or create a PlotCurveItem manually, exactly as done with p1.
Reply all
Reply to author
Forward
0 new messages