using pyqtgraph from atom

243 views
Skip to first unread message

tykom

unread,
Feb 28, 2017, 9:09:18 AM2/28/17
to pyqtgraph
Hi All,

Just started using pyqtgraph and it's pretty great, love the speed. I've gotten the demos to work pretty easily, but I'm trying to add it to a project that I've been developing using atom as an IDE with the Script plugin and the windows that pyqtgraph creates close instantly. This happens if I run the same file from the terminal too. But if I use pyqtgraph directly from terminal, it's fine.

I've followed the tips from this thread to no avail. And searching about hasn't yielded anything promising.

This is the demo code that I've been testing:

import numpy as np
import pyqtgraph as pg
import pyqtgraph.multiprocess as mp
import time

pg.mkQApp()
proc = mp.QtProcess()
rpg = proc._import('pyqtgraph')

win = rpg.GraphicsWindow()
plot1 = win.addPlot()
x = np.linspace(0, 10, 10)
y = np.linspace(-5, 5, 10)
curve = plot1.plot(x, y)    # x,y can be lists, arrays, etc.
curve.setPen('r')
win.show()
time.sleep(2)

adding time.sleep keeps the window open for the specified interval but also defeats the purpose of interactive plotting...

thanks for any help!

tykom

unread,
Feb 28, 2017, 10:35:40 AM2/28/17
to pyqtgraph
Hi again,

this seems to be working:

on linux you can set command options for the Script plugin with the macro shift-control-alt-o and add "-i" to the command arguments to have it run python in interactive mode. You can then save the profile and run later with shift-control-alt-b.

it still seems to be necessary to do all of the initializing the window manually in the code that I put above. Maybe someone can recommend a more succinct way of doing this, though.

vas...@gmail.com

unread,
Feb 28, 2017, 4:04:17 PM2/28/17
to pyqt...@googlegroups.com
#try this way:

import numpy as np
import pyqtgraph as pg
import pyqtgraph.multiprocess as mp
import time

qapp = pg.mkQApp()

proc = mp.QtProcess()
rpg = proc._import('pyqtgraph')

win = rpg.GraphicsWindow()
plot1 = win.addPlot()
curve = plot1.plot()
curve.setPen('r')
win.show()


x = np.linspace(0, 10, 10)
y = np.linspace(-5, 5, 10)
curve.setData(x,y)

# you need to process and set data and call processEvents() in the loop
while win.isVisible():   
    y = y + np.random.random(10) # comment out this row not to update with different value
    curve.setData(x,y) # comment out this row not to update with different value
    qapp.processEvents()

--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/66efd2f5-a78a-418a-b381-ed1cfea87c14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

tykom

unread,
Feb 28, 2017, 11:48:43 PM2/28/17
to pyqtgraph
Thanks, Vasilije!

that is working even without the "-i" workaround I was using.

cheers
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.

vas...@gmail.com

unread,
Mar 1, 2017, 3:05:55 AM3/1/17
to pyqt...@googlegroups.com

On Wed, Mar 1, 2017 at 5:48 AM, tykom <tym...@gmail.com> wrote:
import numpy as np
import pyqtgraph as pg
import pyqtgraph.multiprocess as mp
import time

qapp = pg.mkQApp()
proc = mp.QtProcess()
rpg = proc._import('pyqtgraph')

win = rpg.GraphicsWindow()
plot1 = win.addPlot()
curve = plot1.plot()
curve.setPen('r')
win.show()

x = np.linspace(0, 10, 10)
y = np.linspace(-5, 5, 10)
curve.setData(x,y)

# you need to process and set data and call processEvents() in the loop
while win.isVisible():   
    y = y + np.random.random(10) # comment out this row not to update with different value
    curve.setData(x,y) # comment out this row not to update with different value
    qapp.processEvents()


#also, this works much faster (for me):


import numpy as np
import pyqtgraph as pg

qapp = pg.mkQApp()
win = pg.GraphicsWindow()

plot1 = win.addPlot()
curve = plot1.plot()
curve.setPen('r')
#win.show()

vas...@gmail.com

unread,
Mar 1, 2017, 3:14:02 AM3/1/17
to pyqt...@googlegroups.com
##########################################

import numpy as np
import pyqtgraph as pg

qapp = pg.mkQApp()
win = pg.GraphicsWindow()
plot1 = win.addPlot()
curve = plot1.plot()
curve.setPen('r')
win.show()

x = np.linspace(0, 10, 10)
y = np.linspace(-5, 5, 10)
curve.setData(x,y)

# you need to process and set data and call processEvents() in the loop
while win.isVisible():  
    y = y + np.random.random(10) # comment out this row not to update with different value
    curve.setData(x,y) # comment out this row not to update with different value
    qapp.processEvents()
##########################################

Reply all
Reply to author
Forward
0 new messages