Eolinwen | 2020-05-07 16:33:50 UTC | #1
I run into an issue running in a console : No module named 'plotwidget'.
I'm running on Linux Manjaro with the last version of Python Qt, PyQt and python-pyqtgraph.
An idea about this issue ?
I have redone the GUI but I get still the same behaviour. Strangely, I can't copy the output, she is always removed. That's the first time but here the last lines:
QGraphicsView(QGraphicScene, parent: QWidget = None): argument 1 has unexpected type 'QWidget'
Here the code (under python import)
from pyqtgraph import PlotWidget, plot
import pyqtgraph as pg
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5 import uic
class graPhique(QMainWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
ui_path = "ui/mainwindow.ui"
current_path = os.path.dirname(os.path.realpath(__file__))
ui_file = os.path.join(current_path, ui_path)
uic.loadUi(ui_file, self)
self.plot([1,2,3,4,5,6,7,8,9,10], [30,32,34,32,33,3129,32,35,45])
def plot(self, hour, temperature):
self.graphWidget.plot(hour, temperature)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = graPhique()
window.show()
sys.exit(app.exec_())
I precise that my mainwindow.ui
file is in a sub-folder called ui.
By advance Thanks.
Packaging Python Applications with PyInstaller by Martin Fitzpatrick — This step-by-step guide walks you through packaging your own Python applications from simple examples to complete installers and signed executables.
Eolinwen | 2020-05-07 16:35:00 UTC | #2
I've found a solution. I have had several issues but I've been able to resolve them one after the other.
In QtDesigner/QtCreator. You must put a QGraphicsView and not a QWidget. Select it and promote it. In the screen, you must have QGraphicView. below enter PlotWidgetand still below replace plotwidget by pyqtgraph . Let .h it doesn't matter. Click add and after promote. If you take a look at the tree on the right in Qt/Designer/Creator you should see under centralwidget graphWidget (or by default if you have not modified the objectname graphicsView) and the class call now PlotWidget .
The tutorial code (plot part) is false. And you can see that even the author has forgotten something. The error in the text is between the code and the graph (... which accepts two arrays, temp Temperature and hour Hour, then plots ...). I don't see anything in the code called hour and temp....
Here the good code. I've just added the modified part here.
hour = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
temperature = [30, 32, 34, 32, 33, 31, 29, 32, 35, 45]
# pg.setConfigOption('background', 'w')
self.show_plots(hour, temperature)
def show_plots(self, hour, temperature):
self.graphicsView.plot(hour, temperature, pen=(0,0,255))
# self.PlotWidget.plot(hour, temperature)
Replace graphicView
by graphWidget
if it is like that you have name it.
All should be works fine like me but I'm not an expert. I've not been able to modified the background, ... Perhaps another tutorial with QtDesigner.