Skip to main content

Bindings to use matplotlib components in a QML-like syntax inside of QML-components

Project description

What is this project?

This project is about creating an easy to use interface to use matplotlib plots inside QML with the QML-like syntax.

Check out the Documentation!

Installation guide

Just download from pypi:

pip install matplotlib-qml

or install with a terminal in the repository:

pip install -e .

**If your are installing this package on an Optimizer4D, make sure to add the --no-deps flag to the installation to not overwrite the local PySide2 installation.

Quickstart

If you want to include the bindings in your project to use matplotlib in qml you only need to add these two lines before you initialize your application:

import matplotlib_qml

matplotlib_qml.init()

This will register all plugins for qml.

Example app

In your project directory create two files main.py and main.qml.

main.py:

import sys
from PySide2.QtGui import QGuiApplication
from PySide2.QtQml import QQmlApplicationEngine
from PySide2.QtCore import QUrl

import matplotlib_qml
from pathlib import Path

def main():
    app = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine()

    matplotlib_qml.init()

    qml_file = Path(__file__).parent / "main.qml"
    engine.load(QUrl.fromLocalFile(str(qml_file.resolve())))

    if not engine.rootObjects():
        sys.exit(-1)
    
    sys.exit(app.exec_())


if __name__ == "__main__":
    main()

main.qml:

import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.15

import Matplotlib 1.0

Window {
    id: root
    
    width: 1500
    height: 800
    visible: true
    title: "Hello Python World!"
	
	ColumnLayout {
		anchors.fill: parent
		RowLayout {
			Button {
				text: "HOME"
				onClicked: {
					stack.itemAt(tabbar.currentIndex).home()
				}
			}
			Button {
				text: "BACK"
				onClicked: {
					stack.itemAt(tabbar.currentIndex).back()
				}
			}
			Button {
				text: "FORWARD"
				onClicked: {
					stack.itemAt(tabbar.currentIndex).forward()
				}
			}
			Button {
				text: "PAN"
				onClicked: {
					stack.itemAt(tabbar.currentIndex).pan()
				}
			}
			Button {
				text: "ZOOM"
				onClicked: {
					stack.itemAt(tabbar.currentIndex).zoom()
				}
			}
			Text {
				text: "(" + stack.itemAt(tabbar.currentIndex).coordinates[0].toString() + ", " + stack.itemAt(tabbar.currentIndex).coordinates[1].toString() + ")"
			}			
		}
	
	TabBar {
		id: tabbar
		TabButton {
			text: "1"
			width: 100
		}
		TabButton {
			text: "2"
			width: 100
		}
	}
	StackLayout {
		id: stack
		currentIndex: tabbar.currentIndex
		Figure {
			Layout.fillWidth: true
			Layout.fillHeight: true
			Component.onCompleted: init()
			coordinatesRefreshRate: 1000
			Plot {
				Axis {
					Line {
						xData: [10,20,30]
						yData: [10,20,30]
					}
				}
			}
		}
		Figure {
			Layout.fillWidth: true
			Layout.fillHeight: true
			Component.onCompleted: init()
			coordinatesRefreshRate: 1000
			Plot {
				Axis {
					xMin: 0
					xMax: 10
					yMin: 0
					yMax: 10
					autoscale: ""
					ScatterCollection {
						id: collection
						x: [1,2,3,4,5,6,7,8,9]
						y: [1,2,3,4,5,6,7,8,9]
						c: [1,2,3,4,5,6,7,8,9]
						cMap: "gist_rainbow"
						vMin: 0
						vMax: 10
						colorbar: Colorbar {
							orientation: "horizontal"
							location: "bottom"
							}
						}
					}
				}
			}
		}	
	}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matplotlib_qml_bindings-1.0.1.tar.gz (53.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

matplotlib_qml_bindings-1.0.1-py3-none-any.whl (62.0 kB view details)

Uploaded Python 3

File details

Details for the file matplotlib_qml_bindings-1.0.1.tar.gz.

File metadata

  • Download URL: matplotlib_qml_bindings-1.0.1.tar.gz
  • Upload date:
  • Size: 53.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for matplotlib_qml_bindings-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9a76e755a6f1b2a74e478e2b9326927431dfdeab0accdd3d3c8120424caa93f3
MD5 8821b4336f99811b1487d3f8986e7125
BLAKE2b-256 64f0b30a5683c2e65cfdb1dcb55b813bad407a13bcea74b833cbab6295cb57be

See more details on using hashes here.

File details

Details for the file matplotlib_qml_bindings-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for matplotlib_qml_bindings-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bbc7cd4591dddfde2449700b1b10d72618137343678d8aeae432b482c5335938
MD5 e7990cb76fc3265450a6ebed473ae4f6
BLAKE2b-256 2c433f7e56defb74bf67da572d99eb3f7e4dde2baeaa363af1f8f6c6106a6e67

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page