Fixing "No module named plotwidget" when using PyQtGraph with Qt Designer

How to correctly promote a widget to PyQtGraph's PlotWidget in your .ui files
Heads up! You've already completed this tutorial.

If you've tried using PyQtGraph with a .ui file designed in Qt Designer, you may have run into this frustrating error:

python
No module named 'plotwidget'

Or possibly something like:

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

Both of these errors stem from the same root cause: the widget in Qt Designer hasn't been promoted correctly. The good news is that the fix is straightforward once you understand what's going on.

What's going wrong

When you use uic.loadUi() to load a .ui file at runtime, PyQt6 reads the XML inside that file and constructs your window. If your .ui file contains a promoted widget — like a PyQtGraph PlotWidget — PyQt6 needs to know where to import that widget from.

The "No module named plotwidget" error means Qt Designer saved the import path (the "header file" field) as plotwidget instead of pyqtgraph. So when PyQt6 tries to load the UI, it looks for a Python module called plotwidget, can't find it, and raises an ImportError.

The QGraphicsView type error happens when the base widget in Qt Designer is set to QWidget instead of QGraphicsView. Since PlotWidget is a subclass of QGraphicsView, the promotion needs to start from QGraphicsView.

How to promote the widget correctly in Qt Designer

Here's the correct process, step by step:

  1. Add a QGraphicsView to your form in Qt Designer. This is the base class that PlotWidget inherits from, so it must be QGraphicsView — not a plain QWidget.

  2. Right-click the QGraphicsView and select Promote to....

  3. In the promotion dialog, fill in the fields like this:

  4. Base class name: QGraphicsView (this should already be filled in)

  5. Promoted class name: PlotWidget
  6. Header file: pyqtgraph

Leave the .h extension as-is — Qt Designer shows it because it's designed for C++ too, but PyQt6 ignores the extension and uses the header file field as a Python module path.

  1. Click Add, then click Promote.

After promoting, if you look at the object tree on the right side of Qt Designer, you should see the widget's class listed as PlotWidget instead of QGraphicsView.

That's it for the Designer side. Save your .ui file.

If you're new to Qt Designer, see our Qt Designer tutorial for a complete guide to building interfaces with it.

The Python code

Now let's look at the Python code that loads this UI and uses the promoted widget. Here's a complete working example:

python
import os
import sys

from PyQt6.QtWidgets import QApplication, QMainWindow
from PyQt6 import uic

from pyqtgraph import PlotWidget
import pyqtgraph as pg


class MainWindow(QMainWindow):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # Load the .ui file
        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)

        # Sample data
        hour = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        temperature = [30, 32, 34, 32, 33, 31, 29, 32, 35, 45]

        # Plot the data
        self.graphWidget.plot(hour, temperature)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec())

A few things to note:

  • The from pyqtgraph import PlotWidget import is required even though you don't reference PlotWidget directly in the code. When uic.loadUi() processes the .ui file, it needs PlotWidget to be available in the Python environment. Without this import, you'd get a different error.

  • self.graphWidget refers to the object name of the promoted widget in Qt Designer. If you didn't rename it, it will still be called graphicsView (the default name for a QGraphicsView). You can change the object name in Qt Designer by selecting the widget and editing the objectName property. Use whatever name you set there in your Python code.

  • Make sure the hour and temperature lists have the same length. If they don't, PyQtGraph will raise an error.

Customizing the plot

Once the widget is working, you can customize the appearance. For example, to change the pen color and set a white background:

python
import os
import sys

from PyQt6.QtWidgets import QApplication, QMainWindow
from PyQt6 import uic

from pyqtgraph import PlotWidget
import pyqtgraph as pg


class MainWindow(QMainWindow):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # Load the .ui file
        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)

        # Set the background color to white
        self.graphWidget.setBackground("w")

        # Sample data
        hour = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        temperature = [30, 32, 34, 32, 33, 31, 29, 32, 35, 45]

        # Plot with a blue pen
        pen = pg.mkPen(color=(0, 0, 255), width=2)
        self.graphWidget.plot(hour, temperature, pen=pen)

        # Add axis labels
        self.graphWidget.setLabel("left", "Temperature (°C)")
        self.graphWidget.setLabel("bottom", "Hour")
        self.graphWidget.setTitle("Hourly Temperature")


if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec())

The setBackground("w") method sets the plot background to white. You can use color strings like "w" (white), "k" (black), or RGB tuples like (255, 255, 255). The pg.mkPen() function creates a pen object that controls the line color and width.

For a more in-depth look at PyQtGraph's plotting capabilities, including line styles, fill areas, and multiple plots, see our PyQtGraph plotting tutorial.

Quick reference: promotion fields

If you're ever unsure what to type in the promotion dialog, here's a quick summary:

Field Value
Base class name QGraphicsView
Promoted class name PlotWidget
Header file pyqtgraph

The header file field is what PyQt6 uses as the Python import path. Setting it to pyqtgraph means PyQt6 will effectively do from pyqtgraph import PlotWidget when loading the .ui file — which is exactly what you want.

Common mistakes

Using QWidget as the base class. PlotWidget inherits from QGraphicsView, so promoting from QWidget causes a type mismatch error. Always start with QGraphicsView.

Leaving the header file as plotwidget. Qt Designer sometimes auto-fills this field based on the class name in lowercase. You need to manually change it to pyqtgraph.

Mismatched object names. If your widget is named graphicsView in Qt Designer but your code references self.graphWidget, Python will raise an AttributeError. Check the object name in Qt Designer's property panel and use the same name in your code.

Forgetting to import PlotWidget. Even though you don't use PlotWidget directly in your code, the uic.loadUi() function needs it to be importable. Always include from pyqtgraph import PlotWidget at the top of your script.

With these pieces in place, PyQtGraph and Qt Designer should work together without any issues. You can also embed PyQtGraph widgets as custom widgets in your Qt applications for even more control over integration.

Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak

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.

More info Get the book

Martin Fitzpatrick

Fixing "No module named plotwidget" when using PyQtGraph with Qt Designer 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. Martin founded PythonGUIs to provide easy to follow GUI programming tutorials to the Python community. He has written a number of popular Python books on the subject.