本文整理汇总了Python中matplotlib.backends.backend_qt5agg.NavigationToolbar2QT.addAction方法的典型用法代码示例。如果您正苦于以下问题:Python NavigationToolbar2QT.addAction方法的具体用法?Python NavigationToolbar2QT.addAction怎么用?Python NavigationToolbar2QT.addAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_qt5agg.NavigationToolbar2QT
的用法示例。
在下文中一共展示了NavigationToolbar2QT.addAction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initUI
# 需要导入模块: from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.NavigationToolbar2QT import addAction [as 别名]
def initUI(self):
self.setWindowTitle('NyqLab: Scope')
# Figure
self.figure = plt.figure()
self.canvas = FigureCanvas(self.figure)
toolbar = NavigationToolbar(self.canvas, self)
# Eye diagram toolbar button
action_eye = QtWidgets.QAction(QtGui.QIcon('media/eye'), 'Scope', self)
action_eye.triggered.connect(self.onEyeClick)
toolbar.addAction(action_eye)
# Axis
self.ax_t = self.figure.add_subplot(2, 1, 1)
self.ax_t.grid(True, which='major', linestyle='--')
self.ax_t.set_xlabel('$t / T_\mathrm{b}$')
self.ax_t.axis(self.ax_t_lim_free)
self.ax_t.xaxis.set_major_locator(ticker.MultipleLocator(1.0))
self.ax_t.yaxis.set_major_locator(ticker.MultipleLocator(0.5))
self.ax_f = self.figure.add_subplot(2, 1, 2)
self.ax_f.axis(self.ax_f_lim)
self.ax_f.grid(True, which='major', linestyle='--')
self.ax_f.set_xlabel('$f / R_\mathrm{b}$')
self.ax_f.xaxis.set_major_locator(ticker.MultipleLocator(0.5))
self.ax_f.yaxis.set_major_locator(ticker.MultipleLocator(10.0))
layout = QtWidgets.QVBoxLayout()
layout.addWidget(toolbar)
layout.addWidget(self.canvas)
widget = QtWidgets.QWidget(self)
self.setCentralWidget(widget)
widget.setLayout(layout)
self.resize(800, 500)
示例2: MplWidget
# 需要导入模块: from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT [as 别名]
# 或者: from matplotlib.backends.backend_qt5agg.NavigationToolbar2QT import addAction [as 别名]
class MplWidget(QtWidgets.QWidget):
"""
Widget defined in Qt Designer.
"""
zoom_to_full_view = pyqtSignal()
map_press = pyqtSignal(float, float)
def __init__(self, parent = None):
# initialization of Qt MainWindow widget
QtWidgets.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 = QtWidgets.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.map_press.emit(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.zoom_to_full_view.emit()
def openHelp(self):
"""
Open an Help HTML file
after CADTOOLS module in QG
#.........这里部分代码省略.........