More details regarding "Embedding custom widgets from Qt Designer" and "Creating custom GUI widgets in PyQt5"

I am new to python. After reading “Embedding custom widgets from Qt Designer”, I tried to embed matplotlib into the GUI. I followed the steps until the changing header name in the “promote” step, I entered matplotlib but there is an error msg " cannot import name ‘PlotWidget’ from ‘matplotlib’ (C:\ProgramData\Anaconda3\lib\site-packages\"

I tried matplotlib.plot for the header name then it showed
“cannot import name ‘PlotWidget’ from ‘matplotlib.pyplot’ (C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\”

Is it possible to add more explanations about the correct name of the head in the article? I tried pyqtgraph and it works. I have no idea why it doesn’t work.

I also tried to refer to “Creating custom GUI widgets in PyQt5”. However, I have no idea how to apply the new gui widget in another new main window. I hope there would be more steps and explanations.

Could I know if your book would include more details of those steps?
Thank you very much.

Hi @Revox_Dyna welcome to the forum! Sorry for the delay in getting back to you, I’ve just had a baby and things are a bit busy.

The problem here is that PlotWidget isn’t a matplotlib class, it’s from PyQtGraph which is a different library. To embed matplotlib you would need to use the matplotlib canvas class.

There is another tutorial on matplotlib which shows the class to use – FigureCanvasQTAgg which is imported as follows.

from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg

We can compare that to PyQtGraph, where the PlotWidget is imported as follows.

from pyqtgraph import PlotWidget

When we promote the PlotWidget we use PlotWidget as the name, and pyqtgraph as the header file. The “header file” is the complete package path required to find the class. For matplotlib’s we would give FigureCanvasQTAgg as the name and matplotlib.backends.backend_qt5agg as the header file.

I’ll write up a complete example of this, as it’s not straightforward.

Congratulations on your baby :smile:and
Thank you very much, Martin!
I am looking forward to the example