Code Monkey home page Code Monkey logo

matplotlib_backend_qtquick's Introduction

matplotlib_backend_qtquick

This package implements a QtQuick backend for matplotlib. It started from maplotlib_qtquick_playground, written by Frédéric Collonval, but it has been updated to work with the current version (3.2.1) of matplotlib.

Usage

In order to use matplotlib plots with QtQuick, do the following:

  1. In your main.py, use QtQml.qmlRegisterType to register FigureCanvasQtQuickAgg under whichever name you want to use.
  2. In your QML files, instantiate an object with the QML type defined above. Its objectName property specifies the name of the object that can be found in the QML engine. It can be retrieved in python with win.findChild(QtCore.QObject, "spectFigure"), for example, where "spectFigure" is the objectName in this case.
  3. One can then pass this object as needed. This is the FigureCanvasQtQuickAgg object. The figure can be found in its figure property.

For interactive plots, if you want to use the toolbar, to the Bridge class add slots like:

    @QtCore.Slot()
    def zoom(self, *args):
        """activate zoom tool."""
        self.toolbar.zoom(*args)

One can also connect to Matplotlib events:

       self._figure.canvas.mpl_connect('button_press_event', self.onClick)
       self._figure.canvas.mpl_connect('scroll_event', self.onScroll)

and provide the callbacks, for example:

    def onClick(self, event):
        """
        Handle mouse clicks in the three slices:
        set the slice to what is clicked.
        """
        if event.button == MouseButton.LEFT:
            if event.inaxes == self.axeses[0]:
                self.x = self._findBin(self.xAxis, event.xdata)
                self.y = self._findBin(self.yAxis, event.ydata)
                self.setSlice()
            elif event.inaxes == self.axeses[1]:
                self.x = self._findBin(self.xAxis, event.xdata)
                self.z = self._findBin(self.zAxis, event.ydata)
                self.setSlice()
            elif event.inaxes == self.axeses[2]:
                self.y = self._findBin(self.yAxis, event.xdata)
                self.z = self._findBin(self.zAxis, event.ydata)
                self.setSlice()

    def onScroll(self, event):
        """
        Handle mouse scroll in the three slices
        - scroll the independent variable
        """
        if event.inaxes == self.axeses[0]:
            self.z += int(event.step)
            self.setSlice()
        elif event.inaxes == self.axeses[1]:
            self.y += int(event.step)
            self.setSlice()
        elif event.inaxes == self.axeses[2]:
            self.x += int(event.step)
            self.setSlice()

Please let me know if you have any suggestions or better ways I should do this.

Examples

The example in the examples directory gives a simple example of how to use this backend, including interactions.

matplotlib_backend_qtquick's People

Contributors

jmitrevs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.