本文整理汇总了Python中matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg.layout方法的典型用法代码示例。如果您正苦于以下问题:Python NavigationToolbar2QTAgg.layout方法的具体用法?Python NavigationToolbar2QTAgg.layout怎么用?Python NavigationToolbar2QTAgg.layout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg
的用法示例。
在下文中一共展示了NavigationToolbar2QTAgg.layout方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MplWidget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg import layout [as 别名]
class MplWidget(QtGui.QWidget):
"""Widget defined in Qt Designer"""
def __init__(self, tools, toolbar=True, menu=True, parent=None):
# initialization of Qt MainWindow widget
QtGui.QWidget.__init__(self, parent)
# set the canvas to the Matplotlib widget
self.canvas = MplCanvas()
# create a vertical box layout
self.layout = QtGui.QVBoxLayout()
# add mpl widget to layout
self.layout.addWidget(self.canvas)
# reference to toolsFrame
self.tool = tools
if toolbar:
# add navigation toolbar to layout
self.toolbar = NavigationToolbar(self.canvas, self)
self.layout.addWidget(self.toolbar)
# enable hover event handling
self.setAttribute(Qt.WA_Hover)
# create and install event filter
self.filter = Filter(self)
self.installEventFilter(self.filter)
# hide toolbar
self.initComponents()
else:
self.toolbar = None
# set the layout to th vertical box
self.setLayout(self.layout)
# active lines list
self.lines = []
# legend
self.legend = None
# autoscale
self.canvas.ax.autoscale_view(True, True, True)
if menu:
# setup context menu
self.setContextMenuPolicy(Qt.ActionsContextMenu)
self.initActions()
self.alwaysAutoScale.setChecked(True)
#-------------- initialization ---------------#
def initComponents(self):
if self.toolbar is not None:
self.toolbar.hide()
self.newIcons()
def initActions(self):
# toolbar
self.toggleLegendAction = QtGui.QAction(QtGui.QIcon(RES + ICONS + LEGEND), 'Toggle legend',
self, triggered=self.toggleLegend)
self.toggleLegendAction.setCheckable(True)
if self.toolbar is not None:
self.toolbar.addAction(self.toggleLegendAction)
# context menu
self.addAction(self.toggleLegendAction)
self.addAction(QtGui.QAction(QtGui.QIcon(RES + ICONS + COPY),'Copy data to table',
self, triggered=self.toTable))
self.addAction(QtGui.QAction(QtGui.QIcon(RES + ICONS + GRAPH),'Plot data in tools',
self, triggered=self.toGraphTool))
self.addAction(QtGui.QAction(QtGui.QIcon(RES + ICONS + SCALE), 'Autoscale',
self, triggered=self.updateScale))
self.alwaysAutoScale = QtGui.QAction('Scale on update', self)
self.alwaysAutoScale.setCheckable(True)
self.selectLinesMenu = QtGui.QMenu()
self.selectLines = (QtGui.QAction('Plots', self))
self.selectLines.setMenu(self.selectLinesMenu)
aSep = QtGui.QAction('', self)
aSep.setSeparator(True)
self.addAction(aSep)
self.addAction(self.selectLines)
self.addAction(self.alwaysAutoScale)
def newIcons(self):
for position in range(0, self.toolbar.layout().count()):
widget = self.toolbar.layout().itemAt(position).widget()
if isinstance(widget, QtGui.QToolButton):
icon = QtGui.QIcon(RES + ICONS + TOOLBAR_ICONS[position])
self.toolbar.layout().itemAt(position).widget().setIcon(icon)
self.toolbar.setIconSize(QSize(ICO_GRAPH, ICO_GRAPH))
def resetGraphicEffect(self):
if self.graphicsEffect() is not None:
self.graphicsEffect().setEnabled(False)
#------------- plotting methods ---------------#
## Hides axes in widget.
# @param axes Widget axes form canvas.
@staticmethod
def hideAxes(axes):
axes.get_xaxis().set_visible(False)
axes.get_yaxis().set_visible(False)
#.........这里部分代码省略.........