本文整理汇总了Python中matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg.addAction方法的典型用法代码示例。如果您正苦于以下问题:Python NavigationToolbar2QTAgg.addAction方法的具体用法?Python NavigationToolbar2QTAgg.addAction怎么用?Python NavigationToolbar2QTAgg.addAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg
的用法示例。
在下文中一共展示了NavigationToolbar2QTAgg.addAction方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MplWidget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg import addAction [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)
#.........这里部分代码省略.........
示例2: MplWidget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg import addAction [as 别名]
class MplWidget(QtGui.QWidget):
"""
Widget defined in Qt Designer.
"""
def __init__(self, parent = None):
# initialization of Qt MainWindow widget
QtGui.QWidget.__init__(self, parent)
# set the canvas to the Matplotlib widget
self.canvas = MplCanvas()
self.ntb = NavigationToolbar(self.canvas, self)
#self.ntb.removeAction(self.ntb.buttons[0])
self.ntb.clear()
program_folder = os.path.join(os.path.dirname(__file__), "ims" )
a = self.ntb.addAction(self.ntb._icon(os.path.join(program_folder, "world.png")), 'Home', self.zoom2fullextent)
a.setToolTip('Reset original view')
a = self.ntb.addAction(self.ntb._icon(os.path.join(program_folder, "arrow_left.png")), 'Back', self.ntb.back)
a.setToolTip('Back to previous view')
a = self.ntb.addAction(self.ntb._icon(os.path.join(program_folder, "arrow_right.png")), 'Forward', self.ntb.forward)
a.setToolTip('Forward to next view')
a = self.ntb.addAction(self.ntb._icon(os.path.join(program_folder, "arrow_out.png")), 'Pan', self.ntb.pan)
a.setToolTip('Pan axes with left mouse, zoom with right')
a = self.ntb.addAction(self.ntb._icon(os.path.join(program_folder, "zoom.png")), 'Zoom', self.ntb.zoom)
a.setToolTip('Zoom to rectangle')
action_SetSrcPt = self.ntb.addAction(self.ntb._icon(os.path.join(program_folder, "bullet_red.png")), 'Source point', self.pt_map)
action_SetSrcPt.setToolTip('Set source point in map')
a = self.ntb.addAction(self.ntb._icon(os.path.join(program_folder, "camera.png")), 'Save',
self.ntb.save_figure)
a.setToolTip('Save map as image')
a = self.ntb.addAction(self.ntb._icon(os.path.join(program_folder, "help.png")), 'Help',
self.openHelp)
a.setToolTip('Help')
a = self.ntb.addAction(self.ntb._icon(os.path.join(program_folder, "information.png")), 'About',
self.helpAbout)
a.setToolTip('About')
# create a vertical box layout
self.vbl = QtGui.QVBoxLayout()
# add widgets to the vertical box
self.vbl.addWidget(self.canvas)
self.vbl.addWidget(self.ntb)
# set the layout to the vertical box
self.setLayout(self.vbl)
def onclick(self, event):
"""
Emit a signal to induce the update of source point location.
@param event: press event.
@type event: Matplotlib event.
"""
global set_srcpt_count, cid
set_srcpt_count += 1
if set_srcpt_count == 1:
self.canvas.emit( QtCore.SIGNAL("map_press"), (event.xdata, event.ydata) )
self.canvas.fig.canvas.mpl_disconnect(cid)
def pt_map(self):
"""
Connect the press event with the function for updating the source point location.
"""
global set_srcpt_count, cid
set_srcpt_count = 0
cid = self.canvas.fig.canvas.mpl_connect('button_press_event', self.onclick)
def zoom2fullextent(self):
"""
Emit the signal for updating the map view to the extent of the DEM, in alternative of
the shapefile, or at the standard extent.
"""
self.canvas.emit( QtCore.SIGNAL("zoom_to_full_view") )
# after CADTOOLS module in QG
def openHelp(self):
"""
Open an Help HTML file
#.........这里部分代码省略.........
示例3: initGui
# 需要导入模块: from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.NavigationToolbar2QTAgg import addAction [as 别名]
def initGui( self ):
dsHandle = self.dsHandle
varTup = yield dsHandle( 'variables' )
xVars, yVars = [ [ var[0] for var in indOrDep ] for indOrDep in varTup ]
self.xData = numpy.array( [] ).reshape( 0, len( xVars ) )
self.yData = numpy.array( [] ).reshape( 0, len( yVars ) )
config = self.configDialog = ConfigDialog( self, xVars, yVars, dsHandle )
config.axesChanged.connect( self.newPlotData )
config.setModal( True )
params = yield dsHandle( 'get parameters' )
params = dict( params ) if params is not None else {}
xConfig, yConfigs = params.get( XPLOT ), params.get( YPLOT )
def parseAxis( config, sympyVars ):
if type( config ) is int and config < len( sympyVars ):
return config
if type( config ) is tuple:
foo = getSympyFunc( config[1], sympyVars )
if foo:
return foo
return None
listView = config.xList.listView
tmpSelectionMode = listView.selectionMode()
listView.setSelectionMode( listView.MultiSelection )
tmp = parseAxis( xConfig, config.xList.sympyVars )
if tmp is None: tmp = 0
if type( tmp ) is int:
listView.setCurrentIndex( listView.model().index( tmp, 0, QtCore.QModelIndex() ) )
if callable( tmp ):
count = listView.model().rowCount()
listView.model().addAxis( Map( xConfig[0], tmp, xConfig[1] ) )
listView.setCurrentIndex( listView.model().index( count, 0, QtCore.QModelIndex() ) )
listView.setSelectionMode( tmpSelectionMode )
listView = config.yList.listView
tmpSelectionMode = listView.selectionMode()
listView.setSelectionMode( listView.MultiSelection )
if yConfigs is not None:
for yConfig in yConfigs:
tmp = parseAxis( yConfig, config.yList.sympyVars )
if tmp is not None:
if type( tmp ) is int:
listView.setCurrentIndex( listView.model().index( int, 0, QtCore.QModelIndex() ) )
if callable( tmp ):
count = listView.model().rowCount()
listView.model().addAxis( Map( yConfig[0], tmp, yConfig[1] ) )
listView.setCurrentIndex( listView.model().index( count, 0, QtCore.QModelIndex() ) )
if not listView.selectedIndexes():
listView.setCurrentIndex( listView.model().index( 0, 0, QtCore.QModelIndex() ) )
listView.setSelectionMode( tmpSelectionMode )
self.xPlot = []
self.yPlotModel = YPlotModel( self )
self.fitDialog = FitDialog( self.yPlotModel, self )
self.fig = Figure( ( 5.0, 4.0 ), dpi = 100 )
self.canvas = FigureCanvas( self.fig )
self.canvas.setParent( self )
self.axes = self.fig.add_subplot( 111 )
mpl_toolbar = NavigationToolbar( self.canvas, self )
mpl_toolbar.addAction( QtGui.QIcon( 'icons/fit.svg' ), 'Fit Data', self.fitData ).setToolTip( 'Fit curve to data' )
mpl_toolbar.addAction( QtGui.QIcon( 'icons/removefit.svg' ), 'Remove Fit', self.removeFit ).setToolTip( 'Remove current fit' )
self.layout().addWidget( self.canvas, 1 )
self.layout().addWidget( mpl_toolbar )
editRow = QtGui.QWidget( self )
editRow.setLayout( QtGui.QHBoxLayout() )
rangeMin = self.rangeMin = self.RangeAdjuster( self )
rangeMax = self.rangeMax = self.RangeAdjuster( self )
sliderMin, checkMin = rangeMin.slider, rangeMin.checkBox
sliderMax, checkMax = rangeMax.slider, rangeMax.checkBox
checkMin.setText( 'Anchor min' )
checkMax.setText( 'Anchor max' )
sliderMin.valueChanged.connect( sliderMax.setMinimum )
sliderMax.valueChanged.connect( sliderMin.setMaximum )
sliderMin.valueChanged.connect( lambda min: self.updateRange( 'min', min ) )
sliderMax.valueChanged.connect( lambda max: self.updateRange( 'max', max ) )
self.lengthChanged.connect( lambda length: sliderMax.setMaximum( length ) if not checkMax.isChecked() else None )
self.lengthChanged.connect( lambda length: sliderMax.setValue( length ) if self.following else None )
self.lengthChanged.connect( lambda length: sliderMin.setValue( length - self._tail ) if self.following else None )
checkMin.toggled.connect( lambda checked: sliderMin.setMinimum( sliderMin.value() ) if checked else sliderMin.setMinimum( 0 ) )
checkMax.toggled.connect( lambda checked: sliderMax.setMaximum( sliderMax.value() ) if checked else sliderMax.setMaximum( self.length ) )
editRow.layout().addWidget( rangeMin )
editRow.layout().addWidget( rangeMax )
following = QtGui.QCheckBox( 'Following', self )
following.setChecked( False )
following.toggled.connect( self.followingStateChange )
tail = self.tail = QtGui.QSpinBox( self )
tail.setMinimum( 0 )
tail.setMaximum( 0 )
tail.valueChanged.connect( self.tailChanged )
self.lengthChanged.connect( tail.setMaximum )
editRow.layout().addWidget( following )
#.........这里部分代码省略.........