Instant close plot - Code inside

9 views
Skip to first unread message

Mihai Dimoiu

unread,
May 1, 2018, 3:23:36 PM5/1/18
to pyqtgraph

Hello everyone!

I am writing my problem, my big thank you for your time and help.


So, here is it:

I am creating a GraphicsPlot object, then I add a plot, then I plot pen style with plot(pen='y'). And I have a function which setData in the window created. But this windows closes very fast.

My quest is: How can I keep the plotting window active ?


Here is the code:


from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton
import sys
import pyqtgraph as pg

class GraphPlot(object):
    def __init__(self, title = "Default window title", size_x= 640, size_y = 480):
        
        self.win = pg.GraphicsWindow()
        self.win.resize(size_x, size_y)
        self.win.setWindowTitle(title)
        
        self.graf = self.win.addPlot()
        
        self.curve = self.graf.plot(pen='y')
        
        self.win.show()
        
    def plot(self, data_x):
        self.curve.setData(data_x)
        
        
class AnalyzerApp(QMainWindow):
    def __init__(self):
        super().__init__()
        self.left = 10
        self.top = 10
        self.title = "Title"
        self.width = 1170
        self.height = 720
        self.initUI()
        
    def initUI(self):  
        self.setGeometry(self.left,self.top,self.width,self.height)
        self.setWindowTitle(self.title)
        
        self.btn = QPushButton("Button", self)
        self.btn.move(500, 500)
        self.btn.clicked.connect(self.fxn1) 
        self.show()
        
    def fxn1(self):
        import random
        graf = GraphPlot()
        data = random.sample(range(1,100),3)
        print(data)
        graf.plot(data)
        

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = AnalyzerApp()
    sys.exit(app.exec_())
        
Thank you very much!

Reply all
Reply to author
Forward
0 new messages