matplotlib的QtQuick后端
matplotlib-backend-qtquick的Python项目详细描述
matplotlib_后端\u qtquick
此包实现matplotlib的QtQuick后端。它从maplotlib_qtquick_playground开始,由Frédéric Collonval编写,但是它已经过更新,可以与matplotlib的当前版本(3.2.1)一起使用。在
使用
要将matplotlib plots与QtQuick一起使用,请执行以下操作:
- 在你的主.py,使用
QtQml.qmlRegisterType
将FigureCanvasQtQuickAgg
注册到您想使用的任何名称下。在 - 在QML文件中,用上面定义的QML类型实例化一个对象。它的
objectName
属性指定可以在QML引擎中找到的对象的名称。在python中可以使用win.findChild(QtCore.QObject, "spectFigure")
检索它,例如,"spectFigure"
在本例中是objectName
。在 - 然后可以根据需要传递此对象。这是FigureCanvasQtQuickAgg对象。图可以在其
figure
属性中找到。在
对于交互式绘图,如果要使用工具栏,请在Bridge
类中添加如下插槽:
@QtCore.Slot()defzoom(self,*args):"""activate zoom tool."""self.toolbar.zoom(*args)
也可以连接到Matplotlib事件:
^{pr2}$并提供回调,例如:
defonClick(self,event):""" Handle mouse clicks in the three slices: set the slice to what is clicked. """ifevent.button==MouseButton.LEFT:ifevent.inaxes==self.axeses[0]:self.x=self._findBin(self.xAxis,event.xdata)self.y=self._findBin(self.yAxis,event.ydata)self.setSlice()elifevent.inaxes==self.axeses[1]:self.x=self._findBin(self.xAxis,event.xdata)self.z=self._findBin(self.zAxis,event.ydata)self.setSlice()elifevent.inaxes==self.axeses[2]:self.y=self._findBin(self.yAxis,event.xdata)self.z=self._findBin(self.zAxis,event.ydata)self.setSlice()defonScroll(self,event):""" Handle mouse scroll in the three slices - scroll the independent variable """ifevent.inaxes==self.axeses[0]:self.z+=int(event.step)self.setSlice()elifevent.inaxes==self.axeses[1]:self.y+=int(event.step)self.setSlice()elifevent.inaxes==self.axeses[2]:self.x+=int(event.step)self.setSlice()
请让我知道如果你有任何建议或更好的方法,我应该这样做。在
示例
examples
目录中的示例给出了如何使用这个后端的简单示例,包括交互。在
- 项目
标签: