当前位置: 首页>>代码示例>>Python>>正文


Python FigureCanvasQTAgg.setFocus方法代码示例

本文整理汇总了Python中matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg.setFocus方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasQTAgg.setFocus方法的具体用法?Python FigureCanvasQTAgg.setFocus怎么用?Python FigureCanvasQTAgg.setFocus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg的用法示例。


在下文中一共展示了FigureCanvasQTAgg.setFocus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: LsstCatalogPlot

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocus [as 别名]
class LsstCatalogPlot(QDialog):
    def __init__(self, main, ind, dep, color):
        QDialog.__init__(self, main)
        self.main = main
        self.setPalette(main.palette())
        self.ind = ind
        self.dep = dep
        self.color = color
        self.info = QLabel('Click on a point to highlight the corresponding'
                           ' record')
        self.figure = mpl.figure.Figure()
        self.canvas = FigureCanvasQTAgg(self.figure)
        self.canvas.setParent(self)
        self.canvas.setFocus()

        self.toolbar = NavigationToolbar2QT(self.canvas, self)

        self.ax = self.figure.add_subplot(111)
        self.scatterPlot = self.ax.scatter(self.ind, self.dep, c=self.color,
                                           picker=5, cmap=mpl.cm.YlGnBu_r)
        if self.color is not None:
            self.colorbar = self.figure.colorbar(self.scatterPlot)

        self.canvas.mpl_connect('pick_event', self.main.handleClick)

        vbox = QVBoxLayout()
        vbox.addWidget(self.info)
        vbox.addWidget(self.canvas)
        vbox.addWidget(self.toolbar)
        self.setLayout(vbox)

        self.show()
开发者ID:natelust,项目名称:lsst_explorer,代码行数:34,代码来源:catalog_plotter.py

示例2: ApplicationWindow

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocus [as 别名]
class ApplicationWindow(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)        
        self.initUI()
    def initUI(self):
        self.main_frame = QtGui.QWidget()        
        self.setWindowTitle("Matplotlib Figure in a Qt4 Window with Navigation Toolbar")
        self.fig=Figure() 
        self.axes = self.fig.add_subplot(111)
        self.x = np.arange(0.0, 1.0, 0.01)
        self.y = np.cos(2*np.pi*self.x + 5) + 2
        self.axes.plot(self.x, self.y)
        self.canvas=FigureCanvas(self.fig)
        self.canvas.setParent(self.main_frame)
        self.canvas.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.canvas.setFocus()
        self.ntb = NavigationToolbar(self.canvas, self.main_frame)
        self.canvas.mpl_connect('key_press_event', self.on_key_press)
       
        vbox = QtGui.QVBoxLayout()
        vbox.addWidget(self.canvas)  # the matplotlib canvas
        vbox.addWidget(self.ntb)
        self.main_frame.setLayout(vbox)
        self.setCentralWidget(self.main_frame)

    def on_key_press(self, event):
        print('you pressed', event.key)
        key_press_handler(event, self.canvas, self.ntb)
开发者ID:RavingMadScientist,项目名称:mplEmbed,代码行数:30,代码来源:basicNavWindow.py

示例3: PlotWidget

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocus [as 别名]
class PlotWidget(QWidget):
    def __init__(self):
        super(PlotWidget, self).__init__()
        self.initUI()
        self.data = np.arange(20).reshape([4, 5]).copy()
        self.on_draw()

    def initUI(self):
        self.fig = Figure((5.0, 4.0), dpi=50)
        self.canvas = FigureCanvas(self.fig)
        self.canvas.setParent(self)
        self.canvas.setFocusPolicy(Qt.StrongFocus)
        self.canvas.setFocus()
        # self.mpl_toolbar = NavigationToolbar(self.canvas, self)
        #
        # self.canvas.mpl_connect('key_press_event', self.on_key_press)

        vbox = QVBoxLayout()
        vbox.addWidget(self.canvas)  # the matplotlib canvas
        # vbox.addWidget(self.mpl_toolbar)
        self.setLayout(vbox)

    def on_draw(self):
        self.fig.clear()
        self.axes = self.fig.add_subplot(111)
        # self.axes.plot(self.x, self.y, 'ro')
        self.axes.imshow(self.data, interpolation='nearest')
        # self.axes.plot([1,2,3])
        self.canvas.draw()

    def on_key_press(self, event):
        print('you pressed', event.key)
        # implement the default mpl key press events described at
        # http://matplotlib.org/users/navigation_toolbar.html#navigation-keyboard-shortcuts
        key_press_handler(event, self.canvas, self.mpl_toolbar)
开发者ID:frankbx,项目名称:Volume,代码行数:37,代码来源:plotWidget.py

示例4: PlotWidget

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocus [as 别名]
class PlotWidget(QWidget):
    def __init__(self, name, plotFunction, plot_condition_function_list, plotContextFunction, parent=None):
        QWidget.__init__(self, parent)

        self.__name = name
        self.__plotFunction = plotFunction
        self.__plotContextFunction = plotContextFunction
        self.__plot_conditions = plot_condition_function_list
        """:type: list of functions """
        self.__figure = Figure()
        self.__figure.set_tight_layout(True)
        self.__canvas = FigureCanvas(self.__figure)
        self.__canvas.setParent(self)
        self.__canvas.setFocusPolicy(Qt.StrongFocus)
        self.__canvas.setFocus()

        vbox = QVBoxLayout()
        vbox.addWidget(self.__canvas)
        self.__toolbar = NavigationToolbar(self.__canvas, self)
        vbox.addWidget(self.__toolbar)
        self.setLayout(vbox)

        self.__dirty = True
        self.__active = False
        self.resetPlot()

    def getFigure(self):
        """ :rtype: matplotlib.figure.Figure"""
        return self.__figure

    def resetPlot(self):
        self.__figure.clear()

    def updatePlot(self):
        if self.isDirty() and self.isActive():
            print("Drawing: %s" % self.__name)
            self.resetPlot()
            plot_context = self.__plotContextFunction(self.getFigure())
            self.__plotFunction(plot_context)
            self.__canvas.draw()

            self.setDirty(False)

    def setDirty(self, dirty=True):
        self.__dirty = dirty

    def isDirty(self):
        return self.__dirty

    def setActive(self, active=True):
        self.__active = active

    def isActive(self):
        return self.__active

    def canPlotKey(self, key):
        return any([plotConditionFunction(key) for plotConditionFunction in self.__plot_conditions])
开发者ID:statoil-travis,项目名称:ert,代码行数:59,代码来源:plot_widget.py

示例5: CompactMeasurementMainWindow

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocus [as 别名]
class CompactMeasurementMainWindow(QtGui.QMainWindow, Ui_CompactMeasurementMainWindow):   #or whatever Q*class it is
    def __init__(self, parent=None):
        super(CompactMeasurementMainWindow, self).__init__(parent)
        self.setupUi(self)
        self.fig = Figure((3.0, 2.0), dpi=100)
        self.canvas = FigureCanvas(self.fig)
        self.canvas.setParent(self.centralWidget)
        self.canvas.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.canvas.setFocus()
        self.mpl_toolbar = NavigationToolbar(self.canvas, self.centralWidget)
        self.verticalLayout.addWidget(self.canvas)  # the matplotlib canvas
        self.verticalLayout.addWidget(self.mpl_toolbar)
开发者ID:CoCoMol,项目名称:CoCoPy,代码行数:14,代码来源:CompactGUI.py

示例6: __init__

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocus [as 别名]
 def __init__(self, parent=None):
     QtGui.QWidget.__init__(self, parent)
     figure = Figure()
     fig_canvas = FigureCanvasQTAgg(figure)
     fig_toolbar = NavigationToolbar(fig_canvas, self)
     fig_vbox = QtGui.QVBoxLayout()
     fig_vbox.addWidget(fig_canvas)
     fig_vbox.addWidget(fig_toolbar)
     fig_canvas.setParent(self)
     fig_canvas.setFocusPolicy(QtCore.Qt.ClickFocus)
     fig_canvas.setFocus()
     self.setLayout(fig_vbox)
     self.figure = figure
开发者ID:psalome,项目名称:Satellite,代码行数:15,代码来源:core.py

示例7: _create_canvas

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocus [as 别名]
    def _create_canvas(self, parent):
        """ Create the MPL canvas. """
        # matplotlib commands to create a canvas 
        frame = QtGui.QWidget()
        mpl_canvas = FigureCanvas(self.value)
        mpl_toolbar = NavigationToolbar2QT(parent=frame,canvas = mpl_canvas)
        vbox = QtGui.QVBoxLayout()
        vbox.addWidget(mpl_canvas)
        vbox.addWidget(mpl_toolbar)
        frame.setLayout(vbox)
        mpl_canvas.setFocusPolicy( QtCore.Qt.ClickFocus )
        mpl_canvas.setFocus()

        return frame#mpl_canvas
开发者ID:dialounke,项目名称:pylayers,代码行数:16,代码来源:PylayersGui.py

示例8: GraphViewer

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocus [as 别名]
class GraphViewer(Graphics):
    signalShowTitle = QtCore.pyqtSignal(str)
    signalGraphUpdate = pyqtSignal()
    waitEvent = threading.Event()
    signalPrint = pyqtSignal()
    signalPrintEnd = threading.Event()


    def __init__(self, parent = None):
        Graphics.__init__(self,parent)
        self.parent = parent
        self.create_main_frame()



    def create_main_frame(self):

          self.canvas =  FigureCanvas(self.fig)
          self.canvas2 =  FigureCanvas(self.fig2)
          self.canvas.setParent(self.parent.ui.frame)
          self.canvas.setFocusPolicy(Qt.StrongFocus)
          self.canvas.setFocus()
    #
          self.mpl_toolbar = CustomToolbar(self.canvas, self.parent.ui.mpl,self)
          self.canvas.mpl_connect('pick_event',self.onPick)
          self.canvas.mpl_connect('key_press_event', self.on_key_press)
    #
          self.vbox = QVBoxLayout()
          self.vbox.addWidget(self.canvas)  # the matplotlib canvas
          self.vbox.addWidget(self.canvas2)  # the matplotlib canvas
          self.vbox.addWidget(self.mpl_toolbar)
          self.parent.ui.frame.setLayout(self.vbox)
    #
    # #
          self.fig.clear()
    #
          self.genPlotPage()
          self.genTextPage()
          self.canvas.setVisible(True)
          self.canvas2.setVisible(False)
          self.canvas.setFocusPolicy(Qt.StrongFocus)
          self.canvas.setFocus()
          self.page = 1
          self.signalGraphUpdate.emit()

    def genImage(self):
        self.fig.savefig('../WorkingDir/Page1.png', format='png')
开发者ID:HenricusRex,项目名称:TMV3,代码行数:49,代码来源:GraphViewer.py

示例9: MatplotFrame

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocus [as 别名]
class MatplotFrame(QWidget):

    ## Constructor
    def __init__(self):
        super(MatplotFrame, self).__init__()
        self._figure = plt.figure()
        plt.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1,
                            wspace=0.01, hspace=0.15)
        self._canvas = FigureCanvas(self._figure)
        self._toolbar = NavigationToolbar(self._canvas, self)
        self._updateFunc = None

        layout = QVBoxLayout()
        layout.addWidget(self._toolbar)
        layout.addWidget(self._canvas)
        self.setLayout(layout)
        self._canvas.setFocusPolicy(Qt.StrongFocus)
        self._canvas.setFocus()

    @property
    def figure(self):
        return self._figure

    @property
    def canvas(self):
        return self._canvas

    def initPlot(self, plotFunc):
        plotFunc(self._figure)

    def setUpdateFunc(self, updateFunc):
        self._updateFunc = updateFunc
        self.update()

    def updatePlot(self):
        self._canvas.draw()

    def drawPlots(self, plotFunc):
        self.biginPlot()
        plotFunc()
        self.endPlot()

    def biginPlot(self):
        self._figure.clear()

    def endPlot(self):
        self.updatePlot()
开发者ID:tody411,项目名称:ImageViewerFramework,代码行数:49,代码来源:matplot_frame.py

示例10: AppForm

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocus [as 别名]
class AppForm(QMainWindow):
    def __init__(self, parent=None):
        QMainWindow.__init__(self, parent)
        #self.x, self.y = self.get_data()
        self.data = self.get_data2()
        self.create_main_frame()
        self.on_draw()

    def create_main_frame(self):
        self.main_frame = QWidget()

        self.fig = Figure((5.0, 4.0), dpi=100)
        self.canvas = FigureCanvas(self.fig)
        self.canvas.setParent(self.main_frame)
        self.canvas.setFocusPolicy(Qt.StrongFocus)
        self.canvas.setFocus()

        self.mpl_toolbar = NavigationToolbar(self.canvas, self.main_frame)

        self.canvas.mpl_connect('key_press_event', self.on_key_press)

        vbox = QVBoxLayout()
        vbox.addWidget(self.canvas)  # the matplotlib canvas
        vbox.addWidget(self.mpl_toolbar)
        self.main_frame.setLayout(vbox)
        self.setCentralWidget(self.main_frame)

    def get_data2(self):
        return np.arange(20).reshape([4, 5]).copy()

    def on_draw(self):
        self.fig.clear()
        self.axes = self.fig.add_subplot(111)
        #self.axes.plot(self.x, self.y, 'ro')
        self.axes.imshow(self.data, interpolation='nearest')
        #self.axes.plot([1,2,3])
        self.canvas.draw()

    def on_key_press(self, event):
        print('you pressed', event.key)
        # implement the default mpl key press events described at
        # http://matplotlib.org/users/navigation_toolbar.html#navigation-keyboard-shortcuts
        key_press_handler(event, self.canvas, self.mpl_toolbar)
开发者ID:lynch829,项目名称:radtrack,代码行数:45,代码来源:colour.py

示例11: ApplicationWindow

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocus [as 别名]
class ApplicationWindow(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)        
        self.initUI()
    def initUI(self):
        self.main_frame = QtGui.QWidget()        
        self.setWindowTitle("Matplotlib Figure in a Qt4 Window")
        self.fig=Figure() 
        self.axes = self.fig.add_subplot(111)
        self.x = np.arange(0.0, 1.0, 0.01)
        self.y = np.cos(2*np.pi*self.x + 5) + 2
        self.axes.plot(self.x, self.y)
        self.canvas=FigureCanvas(self.fig)
        self.canvas.setParent(self.main_frame)
        self.canvas.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.canvas.setFocus()
        vbox = QtGui.QVBoxLayout()
        vbox.addWidget(self.canvas)
        self.main_frame.setLayout(vbox)
        self.setCentralWidget(self.main_frame)
开发者ID:RavingMadScientist,项目名称:mplEmbed,代码行数:22,代码来源:basicWindow.py

示例12: _refresh_mpl_widget

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocus [as 别名]
    def _refresh_mpl_widget(self):
        """ Create the mpl widget and update the underlying control.

        """
        # Delete the old widgets in the layout, it's just shenanigans
        # to try to reuse the old widgets when the figure changes.
        widget = self.widget
        layout = widget.layout()
        while layout.count():
            layout_item = layout.takeAt(0)
            layout_item.widget().deleteLater()

        # Create the new figure and toolbar widgets. It seems that key
        # events will not be processed without an mpl figure manager.
        # However, a figure manager will create a new toplevel window,
        # which is certainly not desired in this case. This appears to
        # be a limitation of matplotlib. The canvas is manually set to
        # visible, or QVBoxLayout will ignore it for size hinting.
        figure = self.declaration.figure
        if figure:
            canvas = FigureCanvasQTAgg(figure)
            canvas.setParent(widget)
            canvas.setFocusPolicy(Qt.ClickFocus)
            canvas.setVisible(True)
            canvas.setFocus()
            toolbar = NavigationToolbar2QT(canvas, widget)
            toolbar.setVisible(self.declaration.toolbar_visible)
            if self.declaration.toolbar_location == 'top':
                layout.addWidget(toolbar)
                layout.addWidget(canvas)
            else:
                layout.addWidget(canvas)
                layout.addWidget(toolbar)
            self.last_location = self.declaration.toolbar_location
            if self.declaration.event_actions:
                for event_name, event_action in self.declaration.event_actions:
                    try:
                        if event_name in VALID_EVENTS:
                            canvas.mpl_connect(event_name, event_action)
                    except:
                        pass
开发者ID:alexlib,项目名称:PyDataNYC2015,代码行数:43,代码来源:qt_mpl_canvas.py

示例13: CompactMainWindow

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocus [as 别名]
class CompactMainWindow(QtGui.QMainWindow, Ui_CompactMainWindow):   #or whatever Q*class it is
    def __init__(self):
        super(CompactMainWindow, self).__init__()
        self.setupUi(self)

        self.fig = Figure((3.0, 2.0), dpi=100)
        self.canvas = FigureCanvas(self.fig)
        self.canvas.setParent(self.centralWidget)
        self.canvas.setFocusPolicy(QtCore.Qt.StrongFocus)
        self.canvas.setFocus()
        self.mpl_toolbar = NavigationToolbar(self.canvas, self.centralWidget)
        self.verticalLayout.addWidget(self.canvas)  # the matplotlib canvas
        self.verticalLayout.addWidget(self.mpl_toolbar)
        #self.measDia.clicked.connect(self.openMeasDia)
        self.measMain.clicked.connect(self.openMeasMain)
      
    def openMeasMain(self):
        # here put the code that creates the new window and shows it.
        self.MeasMain = CompactMeasurementMainWindow()
        #self.MeasMain.setupUi(self)
        self.MeasMain.show()
开发者ID:CoCoMol,项目名称:CoCoPy,代码行数:23,代码来源:CompactGUI.py

示例14: MPLWidget

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocus [as 别名]
class MPLWidget(FigureCanvas):
    """
    A widget to contain a matplotlib figure.
    """

    def __init__(self, parent=None, toolbar=False, tight_layout=True,
        autofocus=False, background_hack=True, **kwargs):
        """
        A widget to contain a matplotlib figure.

        :param autofocus: [optional]
            If set to `True`, the figure will be in focus when the mouse hovers
            over it so that keyboard shortcuts/matplotlib events can be used.
        """
        super(MPLWidget, self).__init__(Figure())
        
        self.figure = Figure(tight_layout=tight_layout)
        self.canvas = FigureCanvas(self.figure)
        self.canvas.setParent(parent)

        # Focus the canvas initially.
        self.canvas.setFocusPolicy(QtCore.Qt.WheelFocus)
        self.canvas.setFocus()

        self.toolbar = None 

        if autofocus:
            self._autofocus_cid = self.canvas.mpl_connect(
                "figure_enter_event", self._focus)


        self.figure.patch.set_facecolor([v/255. for v in 
            self.palette().color(QtGui.QPalette.Window).getRgb()[:3]])

        return None


    def _focus(self, event):
        """ Set the focus of the canvas. """
        self.canvas.setFocus()
开发者ID:andycasey,项目名称:pyside-intro,代码行数:42,代码来源:mpl.py

示例15: AppForm

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocus [as 别名]
    class AppForm(QMainWindow):
        def __init__(self, fig):
            parent = None
            QMainWindow.__init__(self, parent)
            self.create_main_frame(fig)
            self.on_draw()

        def create_main_frame(self, fig):
            from matplotlib.backends.backend_qt4agg import (
                FigureCanvasQTAgg as FigureCanvas,
                NavigationToolbar2QT as NavigationToolbar,
            )

            self.main_frame = QWidget()
            self.fig = fig
            self.canvas = FigureCanvas(self.fig)
            self.canvas.setParent(self.main_frame)
            self.canvas.setFocusPolicy(Qt.StrongFocus)
            self.canvas.setFocus()

            self.mpl_toolbar = NavigationToolbar(self.canvas, self.main_frame)

            self.canvas.mpl_connect("key_press_event", self.on_key_press)

            vbox = QVBoxLayout()
            vbox.addWidget(self.canvas)  # the matplotlib canvas
            vbox.addWidget(self.mpl_toolbar)
            self.main_frame.setLayout(vbox)
            self.setCentralWidget(self.main_frame)

        def on_draw(self):
            self.canvas.draw()

        def on_key_press(self, event):
            from matplotlib.backend_bases import key_press_handler

            print("you pressed", event.key)
            # implement the default mpl key press events described at
            # http://matplotlib.org/users/navigation_toolbar.html
            key_press_handler(event, self.canvas, self.mpl_toolbar)
开发者ID:goerz,项目名称:mgplottools,代码行数:42,代码来源:mpl.py


注:本文中的matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg.setFocus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。