I'm trying to make a program in which an instance sends values to another 
instance and it plots them continuously. 


I programmed this using pypubsub to send values from one instance to the 
other. 


The other instance gets values and store them into a deque, and it plots 
the deque whenever it is updates. 


I think the instances communicate with one another well and I can see the 
deque is updated every second as I planned, 


however, the problem is that the graph doesn't show the deque's values 
whenever it is updated, but rather it shows the values 


once the whole updating has finished. I'd like to know how I can plot the 
deque whenever it is updated.




from pyqtgraph.Qt import QtGui, QtCoreimport pyqtgraph as pg
from collections import dequefrom pubsub import pubimport time 

class Plotter:
    def __init__(self):

        self.deq = deque()

        self.pw = pg.GraphicsView()
        self.pw.show()
        self.mainLayout = pg.GraphicsLayout()
        self.pw.setCentralItem(self.mainLayout)
        self.p1 = pg.PlotItem()       
        self.p1.setClipToView=True
        self.curve_1 = self.p1.plot(pen=None, symbol='o', symbolPen=None, 
symbolSize=10, symbolBrush=(102, 000, 000, 255))
        self.mainLayout.addItem(self.p1, row = 0, col=0, rowspan=2)             
            

    def plot(self, msg):
        print('Plotter received: ', msg)
        self.deq.append(msg)
        print(self.deq)
        self.curve_1.setData(self.deq)

class Sender:
    def __init__(self):
        self.list01 = [1,2,3,4,5]            # A list of values that will be 
sent through pub.sendMessage

    def send(self):
        for i in range(len(self.list01)):
            pub.sendMessage('update', msg = self.list01[i] )        
            time.sleep(1)


plotterObj = Plotter()    
senderObj = Sender()

pub.subscribe(plotterObj.plot, 'update')

senderObj.send()




>>> (executing file "<tmp 1>")

Plotter received: 1

deque([1])

Plotter received: 2

deque([1, 2])

Plotter received: 3

deque([1, 2, 3])

Plotter received: 4

deque([1, 2, 3, 4])

Plotter received: 5

deque([1, 2, 3, 4, 5])


-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/912108af-e817-4183-a4f8-8763fb502379%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to