Matplotlib with QtQuick (QML)

Hello!
Is there any chance to find example (in the book, or in this site/forum) how to make the simplest plot using matplotlib but with QtQuick in QML? I’m really confused about the basics, I want to add really simple graph to new window.

Hi @gpbak9611300 welcome to the forum!

I unfortunately don’t have an example for this yet, and am not 100% sure it is possible without quite a bit of work. The matplotlib Qt support is based around the Qt Widgets API, which is entirely separate from QML UIs, so you can’t use the matplotlib Qt widgets in your QML application.

However, the matplotlib backend actually just generates an image and renders that onto a widget’s pixmap. It might be possible to do this, applying the resulting image to a pixmap object in a QML view – I think you’d effectively need to write a custom backend for matplotlib though.

Since it’s a simple plot, would it be possible to use QtGraph to plot it? That’s native and available in QML.

@martin Thanks for the info!

Actually I’ve found backend for QML (matplotlib-backend-qtquick · PyPI)
but using it… its quite complicated for me (a newbie in QML). Anywany I’ll try, and share the result :wink:

But I’m wondering… Is there a way to open QtWidgets (or just other… window like in some IDE) in external window or externall app, and still have active QML app?

1 Like

Hi @gpbak9611300, nice find!

Having looking into adding widgets to QML apps, apparently it’s not possible – there were ways to embed widgets in earlier versions of QML but they’ve been removed.

I’m out of the office this week, but back from next Monday. If you haven’t figured it out by then I’ll have a go, the description does make it look quite complicated but I think it should be possible to get a simple example together.