Embedding pyqtgraph in enaml... how? - python

I'm quite new to pyqt and pyqtgraph so my apology if I'm missing basic things.
I have python program that acquires and plots data, where GUI is implemented by enaml. However the speed of MPL Canvas (matplotlib) was intolerably slow for realtime plotting application, therefore I wish to enhance the performance utilizing pyqtgraph. Immediate conflict seen is that enaml needs to have
from enaml.qt.qt_application import QtApplication
app=QtApplication()
while in order to use pyqtgraph the following seems necessary.
from pyqtgraph.Qt import QtGui, QtCore
app = QtGui.QApplication([])
Can enaml and pyqtgraph coexist or can at least embed pyqtgraph within the enaml thread? If someone can give me a clue it would be a great help. Thanks.

Yes they can exist together. You can create your own declaration and toolkit widgets or use the one from enamlx.
There's an example https://github.com/frmdstryr/enamlx/blob/master/examples/plot_area/plot_area.enaml

Related

How to embed PyQtGraph in QML with a PySide2 Python Backend?

Due to license restrictions I do not want to use QTCharts, so I am looking at PyQtGraph library.
I am working with PySide2 and QML. I am having difficulty getting a simple example working using QML because I don't know where to start. How do I embed one of these charts from the Python/Pyside2 backend to the QML front end?
Do I need to use a QQuickWidget somehow? Anyone have any examples of how to do this?
Can someone please point me in the right direction? Thank you
pyqtgraph is based on QGraphicsView which is part of the Qt Widgets submodule, so what you are asking for is equivalent to asking that a Qt Widget be embedded in QML and that is not possible. QQuickWidget does the opposite, ie embed a QML in a Qt Widget. In conclusion you can not.

Embedding a PyQtGraph into a Tkinter GUI

I have a Tkinter GUI I've been working on for some time that has a live-plotting feature currently built in matplotlib. However, I'm finding matplotlib to be too slow (it seems to build up a lag over time, as if filling up a buffer of frames of incoming data), so I'm thinking of switching my plotting to PyQtGraph. Can I put this into my Tkinter app?
No, you cannot embed a PyQtGraph Object inside a tkinter application.

pyqt5 closeEvent issue with matplotlib FigureCanvas

I wants to build some GUI for retrieving and displaying some data in real time. So I though of embedding a matplotlib figure in a pyqt5 GUI, and followed this example here (https://matplotlib.org/examples/user_interfaces/embedding_in_qt5.html). However, there will be some resource for my application that require a safe destruction at exit. So I tried to overwrite the closeEvent() function of MyMplCanvas with
def closeEvent(self,ce):
print('closeEvent')
super().closeEvent(ce)
But it does not seem to show up when I run the program. Is this expected or is there anything wrong with the program? If this is not the proper way to do so, what is the right way to do some clean-up during the destruction of a QWidget?
Thanks a lot!

Cannot run matplotlib and pyqt4 at the same time

I am running some code using PyQt4, and I would like to plot a figure using its data. But when I try to do that, it will report
QPixmap: Must construct a QGuiApplication before a QPixmap
Below is the code:
from PyQt4 import QtCore
import sys
import matplotlib.pyplot as plt
import numpy as np
def run():
#here is some code, I delete them since they are useless for this question
return data1 #data1 is a list with 30 elements
app = QtCore.QCoreApplication(sys.argv)
client.finished.connect(app.quit)
QtCore.QTimer().singleShot(0,lambda:client.timed_range_stream(5000))
app.exec_()
fig = plt.figure()
ax1 = fig.add_subplot(111)
data2 = run()
datalen = np.linspace(0,10,len(data2))
ax1.plot(datalen,data2,lw = 2)
plt.show()
Since the matplotlib is using pyqt4 as backend, I am so confused why this error happened. It should create a QGuiApplication automatically. I mean whether I use pyqt4 before or not, the code below 'app.exec_()' should create a QGuiApplication automatically. Please point out if I am wrong.
Really appreciate your help! Please give me some advice.
The complaint by PyQt is that you are not running a Gui EventLoop. app.exec_() sure starts an event loop, but that depends on what app is. In your case its QCoreApplication object. How do you expect it to start a Gui EventLoop? It's like buying a saucepan and expecting it to cook pizza.
matplotlib is based on PyQt for sure. I'm sure you can use it in console only applications as well. Hence PyQt will not be able to tell if you want a gui or a console app.
QCoreApplication is used when you are writing a console-based application. Fewer events and processes to manage. If you want to show a window, even a simple one, it takes much more work. And the beast to handle that extra work in QGuiApplication
Now to the Qt version. You are using PyQt4, but the complaint says you need to create a QGuiApplication. However, there is no QGuiApplication or any reference to it in Qt4/PyQt4. This leads me to believe that, your matplotlib copy might be using PyQt5, or PyQt5 dependency comes in from some obscure source, I'm not sure. Check the details of the PyQt version used.
If you are using PyQt4 add from PyQt4 import QtGui in the beginning.
Then change the app = QtCore.QCoreApplication(...) to app = QtGui.QApplication(...).
In case of PyQt5 add from PyQt5 import QtGui, QtWidgets in the beginning.
Then change the app = QtCore.QCoreApplication(...) to app = QtWidgets.QApplication(...).
That'll solve your problem.
PS: Remember, you cannot mix PyQt4 and PyQt5.

Best Qt Widget to use for properties window... in PySide?

This question is the exact same as this one except that I'm looking for such a widget to be used in PySide. Anyone knows some code out there that provide easy-to-reuse property editor widget?
There is the proposal of using QTreeView or QTableView to build such a widget that is an option with PySide, but this is not a straight forward solution...
I don't know if you would be OK with this, but if you are happy to add the whole of pyqtgraph as a dependency, then you might want to try using pyqtgraph's ParameterTree.
There is a pretty comprehensive set of examples, just install pyqtgraph and then run:
import pyqtgraph.examples
pyqtgraph.examples.run()
Launch the ParameterTree example!

Categories

Resources