本文整理汇总了Python中matplotlib.backends.backend_qt4.NavigationToolbar2QT类的典型用法代码示例。如果您正苦于以下问题:Python NavigationToolbar2QT类的具体用法?Python NavigationToolbar2QT怎么用?Python NavigationToolbar2QT使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NavigationToolbar2QT类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, canvas, frame, name=None):
""" Create a new toolbar object
Parameters
----------
data_collection : DataCollection instance
The data collection that this toolbar is meant to edit.
The toolbar looks to this collection for the available subsets
to manipulate.
canvas : Maptloblib canvas instance
The drawing canvas to interact with
frame : QWidget
The QT frame that the canvas is embedded within.
"""
self.buttons = {}
self.__active = None
self.basedir = None
NavigationToolbar2QT.__init__(self, canvas, frame)
if name is not None:
self.setWindowTitle(name)
self.setIconSize(QtCore.QSize(25, 25))
self.layout().setSpacing(1)
self.setFocusPolicy(Qt.StrongFocus)
self._idKey = None
# pyside is prone to segfaults if slots hold the only
# reference to a signal, so we hold an extra reference
# see https://bugreports.qt-project.org/browse/PYSIDE-88
self.__signals = []
示例2: _init_toolbar
def _init_toolbar(self):
NavigationToolbar2QT._init_toolbar(self)
# adding a new icon
icon=QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/MPL Toolbar/export_ascii.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
a=self.addAction(icon, "Export", self.export_ascii)
a.setToolTip('Export the plot into ASCII file')
示例3: __init__
def __init__(self, canvas, parent, coordinates=True):
"""
Constructor of NavToolBar
:param canvas: the matplotlib canvas
:type canvas: matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg
:param parent: the parent QWidget
:type parent: PyQt4.QtGui.QWidget
:param coordinates: boolean coordinates
:type coordinates: bool
"""
NavigationToolbar2QT.__init__(self, canvas, parent, coordinates)
self.setIconSize(QSize(16, 16))
示例4: __init__
def __init__(self, canvas, frame, name=None):
""" Create a new toolbar object
Parameters
----------
data_collection : DataCollection instance
The data collection that this toolbar is meant to edit.
The toolbar looks to this collection for the available subsets
to manipulate.
canvas : Maptloblib canvas instance
The drawing canvas to interact with
frame : QWidget
The QT frame that the canvas is embedded within.
"""
self.buttons = {}
self.basedir = None
NavigationToolbar2QT.__init__(self, canvas, frame)
if name is not None:
self.setWindowTitle(name)
self.setIconSize(QtCore.QSize(25, 25))
self.layout().setSpacing(1)
self.setFocusPolicy(Qt.StrongFocus)
示例5: __init__
def __init__(self):
Qt.QMainWindow.__init__(self, None)
# "application main window",
# Qt.WType_TopLevel | Qt.WDestructiveClose)
self.file_menu = Qt.QMenu("&File", self)
self.file_menu.addAction("&Quit", self.fileQuit, Qt.Qt.CTRL + Qt.Qt.Key_Q)
self.menuBar().addMenu(self.file_menu)
self.help_menu = Qt.QMenu("&Help", self)
self.menuBar().addSeparator()
self.menuBar().addMenu(self.help_menu)
self.help_menu.addAction("&About", self.about)
self.main_widget = Qt.QWidget(self)
l = Qt.QVBoxLayout(self.main_widget)
sc = MyPylabPlotter(self.main_widget, dpi=100)
toolbar = NavigationToolbar(sc, self.main_widget)
toolbar.setSizePolicy(Qt.QSizePolicy.Expanding, Qt.QSizePolicy.Fixed)
l.addWidget(sc)
l.addWidget(toolbar)
self.main_widget.setFocus()
self.setCentralWidget(self.main_widget)
# Produce a plot that is contained in MyPylabPlotter
sc.demo_pythonic_matplotlib()
# Produce a plot that is separate from MyPylabPlotter
sc.demo_pylab_figure()
示例6: MPL_Widget
class MPL_Widget(QtGui.QWidget):
def __init__(self, parent = None):
QtGui.QWidget.__init__(self, parent)
self.canvas = MyMplCanvas()
#self.toolbar = MyNavigationToolbar(self.canvas, self.canvas, direction = 'v')
self.toolbar = NavigationToolbar(self.canvas, self.canvas)
#self.toolbar.hide()
self.hbox = QtGui.QHBoxLayout()
#self.hbox.addWidget(self.toolbar)
self.hbox.addWidget(self.canvas)
self.setLayout(self.hbox)
##########################
self.hZoom = QtGui.QAction("Zoom", self)
self.hZoom.setShortcut("Ctrl+Z")
self.addAction(self.hZoom)
QtCore.QObject.connect(self.hZoom,QtCore.SIGNAL("triggered()"), self.ZoomToggle)
self.actionAutoScale = QtGui.QAction("AutoScale", self)#self.MainWindow)
self.actionAutoScale.setShortcut("Ctrl+A")
self.addAction(self.actionAutoScale)
QtCore.QObject.connect(self.actionAutoScale,QtCore.SIGNAL("triggered()"), self.autoscale_plot)
def ZoomToggle(self):
self.toolbar.zoom()
def autoscale_plot(self):
self.toolbar.home()
示例7: __init__
def __init__(self , canvas , parent , direction = 'h' ) :
#NavigationToolbar.__init__(self,parent,canvas)
#self.layout = QVBoxLayout( self )
self.canvas = canvas
QtGui.QWidget.__init__( self, parent )
if direction=='h' : self.layout = QtGui.QHBoxLayout( self )
else : self.layout = QtGui.QVBoxLayout( self )
self.layout.setMargin( 2 )
self.layout.setSpacing( 0 )
NavigationToolbar.__init__( self, canvas, parent )
示例8: __init__
def __init__(self, parent = None):
QtGui.QWidget.__init__(self, parent)
self.canvas = MyMplCanvas()
#self.toolbar = MyNavigationToolbar(self.canvas, self.canvas, direction = 'v')
self.toolbar = NavigationToolbar(self.canvas, self.canvas)
self.toolbar.hide()
self.hbox = QtGui.QHBoxLayout()
#self.hbox.addWidget(self.toolbar)
self.hbox.addWidget(self.canvas)
self.setLayout(self.hbox)
##########################
self.hZoom = QtGui.QAction("Zoom", self)
self.hZoom.setShortcut("Ctrl+Z")
self.addAction(self.hZoom)
QtCore.QObject.connect(self.hZoom,QtCore.SIGNAL("triggered()"), self.ZoomToggle)
self.actionAutoScale = QtGui.QAction("AutoScale", self)#self.MainWindow)
self.actionAutoScale.setShortcut("Ctrl+A")
self.addAction(self.actionAutoScale)
QtCore.QObject.connect(self.actionAutoScale,QtCore.SIGNAL("triggered()"), self.autoscale_plot)
self.installEventFilter(EventFilter(self))
###########SAVING FIGURE TO CLIPBOARD##########
self.cb = None #will be used for the clipboard
self.tempPath = getHomeDir()
self.tempPath = os.path.join(self.tempPath,'tempMPL.png')
示例9: show_pylab_plot
def show_pylab_plot(self, store_rec=True):
""" process incoming data and attributes into the
appropriate type of plot """
# if we are single stepping through requests, Oleg may reset the
# cache, so check for a non-data record situation
if store_rec and isinstance(self._rec, bool):
return
pylab_record = self._rec.plotdefs
if not self._pylab_plotter is None:
# self._pylab_plotter.reparent(Qt.QWidget(), 0, Qt.QPoint())
self._pylab_plotter.setParent(Qt.QWidget())
self._pylab_plotter = None
if not self._toolbar is None:
# self._toolbar.reparent(Qt.QWidget(), 0, Qt.QPoint())
self._toolbar.setParent(Qt.QWidget())
self._toolbar = None
if self._pylab_plotter is None:
self._pylab_plotter = MyPylabPlotter(parent=self.layout_parent)
self.layout.addWidget(self._pylab_plotter, 1, 0)
self._pylab_plotter.show()
if self._toolbar is None:
self._toolbar = NavigationToolbar(self._pylab_plotter, self.layout_parent)
self._toolbar.setSizePolicy(Qt.QSizePolicy.Expanding, Qt.QSizePolicy.Fixed)
self.layout.addWidget(self._toolbar, 0, 0)
self._toolbar.show()
self._pylab_plotter.make_plot(pylab_record)
示例10: __init__
def __init__(self, parent=None):
# initialization of the superclass
super(ArchaeoPYMainWindow, self).__init__(parent)
# setup the GUI --> function generated by pyuic4
self.setupUi(self)
# Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons
self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self)
self.navi_toolbar.clear()
# Adds Buttons
a = self.navi_toolbar.addAction(self.navi_toolbar._icon("home.png"), "Home", self.navi_toolbar.home)
# a.setToolTip('returns axes to original position')
a = self.navi_toolbar.addAction(self.navi_toolbar._icon("move.png"), "Pan", self.navi_toolbar.pan)
a.setToolTip("Pan axes with left mouse, zoom with right")
a = self.navi_toolbar.addAction(self.navi_toolbar._icon("zoom_to_rect.png"), "Zoom", self.navi_toolbar.zoom)
a.setToolTip("Zoom to Rectangle")
a = self.navi_toolbar.addAction(self.navi_toolbar._icon("filesave.png"), "Save", self.navi_toolbar.save_figure)
a.setToolTip("Save the figure")
QtGui.QShortcut(QtGui.QKeySequence("Ctrl+C"), self, self.copy_to_clipboard)
# self.xlabel = QtGui.QInputDialog.getText(self, 'X-axis Label')
# Button_layout is a QT desginer Grid Layout.
self.toolbar_grid.addWidget(self.navi_toolbar)
self.button_grid()
示例11: __init__
def __init__(self, parent = None):
# initialization of the superclass
super(ArchaeoPYMainWindow, self).__init__(parent)
# setup the GUI --> function generated by pyuic4
self.setupUi(self)
#Adds a Matplotlib Toolbar to the display, clears the display and adds only the required buttons
self.navi_toolbar = NavigationToolbar(self.mpl.canvas, self)
self.navi_toolbar.clear()
#Adds Buttons
a = self.navi_toolbar.addAction(self.navi_toolbar._icon('home.png'), 'Home',
self.navi_toolbar.home)
#a.setToolTip('returns axes to original position')
a = self.navi_toolbar.addAction(self.navi_toolbar._icon('move.png'), 'Pan',
self.navi_toolbar.pan)
a.setToolTip('Pan axes with left mouse, zoom with right')
a = self.navi_toolbar.addAction(self.navi_toolbar._icon('zoom_to_rect.png'), 'Zoom',
self.navi_toolbar.zoom)
a.setToolTip('Zoom to Rectangle')
a = self.navi_toolbar.addAction(self.navi_toolbar._icon('filesave.png'), 'Save',
self.navi_toolbar.save_figure)
a.setToolTip('Save the figure')
#Button_layout is a QT desginer Grid Layout.
self.toolbar_grid.addWidget(self.navi_toolbar)
self.Button_Definitions()
self.plot_options()
示例12: PlotWidget
class PlotWidget(QtGui.QWidget):
"""This class represents the plot view for plotting graphs.
:returns: an instance of *PlotWidget*
"""
def __init__(self,):
QtGui.QWidget.__init__(self)
self.figure = Figure(facecolor=(1, 1, 1), tight_layout=True)
self.ax = self.figure.add_subplot(111)
# Canvas
self.canvas = FigureCanvas(self.figure)
self.canvas.setSizePolicy(QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding)
self.canvas.updateGeometry()
# Navigation
self.navi_toolbar = NavigationToolbar(self.canvas, self)
self.navi_toolbar.setOrientation(QtCore.Qt.Vertical)
# Fixed with, otherwise navigation bar resize arbitrary
self.navi_toolbar.setFixedWidth(40)
self.vbl = QtGui.QHBoxLayout()
self.vbl.addWidget(self.navi_toolbar)
self.vbl.addWidget(self.canvas)
self.setLayout(self.vbl)
def plot(self, x_data_1, y_data_1, x_data_2, y_data_2):
"""Plot given data on *PlotWidget*.
:param x_data_1: X-axis data for plot 1
:type x_data_1: array_like
:param y_data_1: Y-axis data for plot 1
:type y_data_1: array_like
:param x_data_2: X-axis data for plot 2
:type x_data_2: array_like
:param y_data_2: Y-axis data for plot 2
:type y_data_2: array_like
"""
self.ax.clear()
self.ax.grid(True)
self.ax.plot(x_data_1, y_data_1, 'b^', label='Input Data')
self.ax.plot(x_data_2, y_data_2, 'b-', label='Fitted Data')
self.ax.legend()
self.canvas.draw()
示例13: MatplotlibWidget
class MatplotlibWidget(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.frame = QWidget()
self.canvas = MplCanvas()
self.canvas.setParent(self.frame)
self.mpltoolbar = Navigationtoolbar(self.canvas, self.frame)
self.vbl = QtGui.QVBoxLayout()
self.vbl.addWidget(self.canvas)
self.vbl.addWidget(self.mpltoolbar)
self.setLayout(self.vbl)
self.mpltoolbar.toggleViewAction()
def setTitle(self, text):
"""
Sets the figure title
"""
self.canvas.setTitle(text)
def get_axis(self):
return self.canvas.ax
def get_figure(self):
return self.canvas.fig
def clear(self, force=False):
if force:
self.canvas.fig.clear()
self.canvas.ax = self.canvas.fig.add_subplot(111)
# self.canvas.ax.clear()
# self.canvas = MplCanvas()
else:
self.canvas.ax.clear()
def redraw(self):
self.canvas.ax.figure.canvas.draw()
def plot(self, x, y, title='', xlabel='', ylabel=''):
self.setTitle(title)
self.canvas.ax.plot(x, y)
self.redraw()
示例14: init_plots
def init_plots(self):
""" Initialize plots used in plugin """
self.plot_dock = QtGui.QDockWidget('TSTools Plots',
self.iface.mainWindow())
self.plot_dock.setObjectName('TSTools Plots')
settings.plot_dirty = []
for plot in plots.plots:
self.plots.append(plot(self.iface))
settings.plot_dirty.append(False)
self.plot_tabs = QtGui.QTabWidget(self.plot_dock)
@QtCore.pyqtSlot(int)
def tab_changed(idx):
""" Updates current tab index & re-plots if needed """
settings.plot_current = idx
if settings.plot_dirty[idx]:
self.plots[idx].plot()
settings.plot_dirty[idx] = False
self.plot_tabs.currentChanged.connect(tab_changed)
for plot in self.plots:
widget = QtGui.QWidget()
layout = QtGui.QHBoxLayout()
nav = NavigationToolbar(plot, widget, coordinates=False)
nav.setOrientation(QtCore.Qt.Vertical)
nav.setSizePolicy(QtGui.QSizePolicy.Fixed,
QtGui.QSizePolicy.Fixed)
plot.setSizePolicy(QtGui.QSizePolicy.Preferred,
QtGui.QSizePolicy.Preferred)
layout.addWidget(nav)
layout.addWidget(plot)
widget.setLayout(layout)
self.plot_tabs.addTab(widget, plot.__str__())
self.plot_dock.setWidget(self.plot_tabs)
self.iface.addDockWidget(QtCore.Qt.BottomDockWidgetArea,
self.plot_dock)
示例15: __init__
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.frame = QWidget()
self.canvas = MplCanvas()
self.canvas.setParent(self.frame)
self.mpltoolbar = Navigationtoolbar(self.canvas, self.frame)
self.vbl = QtGui.QVBoxLayout()
self.vbl.addWidget(self.canvas)
self.vbl.addWidget(self.mpltoolbar)
self.setLayout(self.vbl)
self.mpltoolbar.toggleViewAction()