PyQtGraph issue running in console

Heads up! You've already completed this tutorial.

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:

python
QGraphicsView(QGraphicScene, parent: QWidget = None): argument 1 has unexpected type 'QWidget'

Here the code (under python import)

python
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(graPhique, self).__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.


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.

python
       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.


The complete guide to packaging Python GUI applications with PyInstaller.
[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]

Purchasing Power Parity

Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]
Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak

PyQtGraph issue running in console was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt.