I did some examples with PyQtGraph that run fine contained in they're own files, but when I create a Class that inherit from QtGui.QMainWindow and instantiate it from my main.py I get the following error:
Process finished with exit code -1073740791 (0xC0000409)
I notice that I get the above error when the Class gets initialize as follow;
example_1:
class Graph(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
-or-
example_2:
class Graph(QtGui.QMainWindow):
def __init__(self, parent=None):
super(Graph, self).__init__(parent)
But when I initialize my class as below, my program work, but It doesn't plot anything. I just see the Y and X axis (empty plotting widget) there with no plot.
class Graph(QtGui.QMainWindow):
def __init__(self):
super()
Just an example pic
The way I'm passing values from the main to my class is by using a deque for x and y created in my class:
self.x = deque()
self.y = deque()
Then I pass the value from my main.py using:
app = QtGui.QGuiApplication(sys.argv)
plot = graph.Graph()
plot.start()
...
While statement
plot.x.extend([a list of values])
plot.y.extend([a list of values])
Has anyone encounter a similar problem before?
Maybe I just need a pair of extra eyes to identify my issue here. I also found this previous question, but I'm not using multi-thread. Actually when I do use multi-thread in one of my example I don't get initialization problems when initializing the class as shown in my example_1 and example_2 at the beginning of the post.
Can someone point me in the right direction?
I'm more use to matplotlib, but is slow and pyqtgraph is new for me, but I found that is better for real-time plotting. I'm just saying this in case someone suggest me to use one over the other.
Thank you in advance.
Edited 2020-06-30 Added some example code
Using GraphicLayout script from pyqtgraph examples as my base code and Nrecursions example:
In a new script add:
import pyqtgraph.examples
pyqtgraph.examples.run()
# and search for GraphicsLayout
My version of GraphicLayout.py
"""
Demonstrate the use of layouts to control placement of multiple plots / views /
labels
using GraphicsLayout from pyqtgraph_examples
"""
from pyqtgraph.Qt import QtGui, QtCore, QtWidgets
import pyqtgraph as pg
import numpy as np
from collections import deque
class graphiclayout(QtGui.QMainWindow):
def __init__(self, parent=None):
super(graphiclayout,self).__init__(parent)
self.app = QtGui.QApplication([])
self.x = deque([0])
self.y = deque([0])
self.view = pg.GraphicsView()
l = pg.GraphicsLayout(border=(100,100,100))
self.view.setCentralItem(l)
self.view.show()
self.view.setWindowTitle('pyqtgraph example: GraphicsLayout')
self.view.resize(800,600)
## Title at top
self.text = """
This example demonstrates the use of GraphicsLayout to arrange items in a grid.<br>
The items added to the layout must be subclasses of QGraphicsWidget (this includes <br>
PlotItem, ViewBox, LabelItem, and GrphicsLayout itself).
"""
self.l.addLabel(self.text, col=1, colspan=4)
self.l.nextRow()
## Put vertical label on left side
self.l.addLabel('Long Vertical Label', angle=-90, rowspan=3)
## Add 3 plots into the first row (automatic position)
self.p1 = self.l.addPlot(title="Plot 1")
self.p2 = self.l.addPlot(title="Plot 2")
self.vb = self.l.addViewBox(lockAspect=True)
self.img = self.pg.ImageItem(np.random.normal(size=(100,100)))
self.vb.addItem(self.img)
self.vb.autoRange()
## Add a sub-layout into the second row (automatic position)
## The added item should avoid the first column, which is already filled
self.l.nextRow()
self.l2 = l.addLayout(colspan=3, border=(50,0,0))
self.l2.setContentsMargins(10, 10, 10, 10)
self.l2.addLabel("Sub-layout: this layout demonstrates the use of shared axes and axis labels", colspan=3)
self.l2.nextRow()
self.l2.addLabel('Vertical Axis Label', angle=-90, rowspan=2)
self.p21 = self.l2.addPlot()
self.p22 = self.l2.addPlot()
self.l2.nextRow()
self.p23 = self.l2.addPlot()
self.p24 = self.l2.addPlot()
self.l2.nextRow()
self.l2.addLabel("HorizontalAxisLabel", col=1, colspan=2)
## hide axes on some plots
self.p21.hideAxis('bottom')
self.p22.hideAxis('bottom')
self.p22.hideAxis('left')
self.p24.hideAxis('left')
self.p21.hideButtons()
self.p22.hideButtons()
self.p23.hideButtons()
self.p24.hideButtons()
## Add 2 more plots into the third row (manual position)
self.p4 = self.l.addPlot(row=3, col=1)
self.p5 = self.l.addPlot(row=3, col=2, colspan=2)
self.curve1 = self.p1.plot(pen=pg.mkPen(width=1, color='r'))
def update(self):
self.curve1.setData(self.x, self.y)
QtGui.QGuiApplication.processEvents()
def start(self):
self.graphUpdateSpeedMs = 50
self.timer = QtCore.QTimer() # to create a thread that calls a function at intervals
self.timer.timeout.connect(self.update) # the update function keeps getting called at intervals
self.timer.start(self.graphUpdateSpeedMs)
self.QtGui.QApplication.instance().exec_()
My main.py
import sys
import numpy as np
import threading
from pyqtgraph import QtCore, QtGui
from collections import deque
from GraphicLayout import graphiclayout as gl
def testdata():
while True:
g.x.extend([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
g.y.extend([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
if __name__ == "__main__":
# app = QtCore.QCoreApplication(sys.argv)
g = gl()
t1 = threading.Thread(target=testdata)
t1.setDaemon(True)
t1.start()
g.start()
# g.show()
# app.instance().exec_()
My directory structure is as follow:
GraphicsLayout (directory)
|
|----- __init__.py
|----- GraphicLayout.py
|----- main.py
When I run my main.py I get the following error
Process finished with exit code -1073740791 (0xC0000409)
What I'm trying to do is to update a plot adding 1 or more curves into it using different data structures (list, deque, queue, numpy array, etc) from another script, so I can do all the data capture in my main and pass it to GraphicLayout.py. Since I'm new to PyQt5 and PySide2, I'm probably have all this wrong, but can't figure out how to get pass the current error.
User contributions licensed under CC BY-SA 3.0