本文整理汇总了Python中matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg.setFocusPolicy方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasQTAgg.setFocusPolicy方法的具体用法?Python FigureCanvasQTAgg.setFocusPolicy怎么用?Python FigureCanvasQTAgg.setFocusPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg
的用法示例。
在下文中一共展示了FigureCanvasQTAgg.setFocusPolicy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _refresh_mpl_widget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocusPolicy [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)
toolbar = NavigationToolbar2QT(canvas, widget)
toolbar.setVisible(self.declaration.toolbar_visible)
layout.addWidget(toolbar)
layout.addWidget(canvas)
示例2: PlotWidget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocusPolicy [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)
示例3: ApplicationWindow
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocusPolicy [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)
示例4: PlotWidget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocusPolicy [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])
示例5: CompactMeasurementMainWindow
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocusPolicy [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)
示例6: _create_plot
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocusPolicy [as 别名]
def _create_plot(self):
dpi = plt.rcParams['figure.dpi']
figsize = (self._plot_width / dpi, self._plot_height / dpi)
figure = plt.figure(frameon=False, figsize=figsize)
axes = figure.add_subplot(111)
canvas = FigureCanvas(figure)
canvas.setFocusPolicy(QtCore.Qt.ClickFocus)
canvas.setFixedSize(self._plot_width, self._plot_height)
canvas.setStyleSheet("background: transparent")
return axes, canvas
示例7: __init__
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocusPolicy [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
示例8: _create_canvas
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocusPolicy [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
示例9: MatplotlibWidget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocusPolicy [as 别名]
class MatplotlibWidget(QtGui.QWidget):
'''Base matplotlib Qt widget'''
def __init__(self, parent=None, *args, **kwargs):
super(MatplotlibWidget, self).__init__(parent=parent)
self.figure = Figure(*args, **kwargs)
self.canvas = FigureCanvas(self.figure)
self.canvas.setFocusPolicy(QtCore.Qt.ClickFocus)
self.toolbar = NavigationToolbar(self.canvas, self)
layout = QtGui.QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
self.setLayout(layout)
self.canvas.draw()
示例10: _FigureResultMixin
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocusPolicy [as 别名]
class _FigureResultMixin(_SaveableResultMixin):
def __init__(self):
_SaveableResultMixin.__init__(self)
def _createFigure(self):
raise NotImplementedError
def _drawFigure(self):
self._ax.relim()
self._ax.autoscale_view(True, True, True)
self._canvas.draw()
def _initUI(self):
# Variables
figure = self._createFigure()
# Widgets
self._canvas = FigureCanvas(figure)
self._canvas.setFocusPolicy(Qt.StrongFocus)
self._canvas.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self._canvas.updateGeometry()
# Layouts
layout = super(_FigureResultMixin, self)._initUI()
layout.addWidget(self._canvas, 1)
# Defaults
for ext_name, exts in \
self._canvas.get_supported_filetypes_grouped().items():
self._register_save_method(ext_name, exts, self._canvas.print_figure)
return layout
def _initToolbar(self):
toolbar = NavigationToolbar(self._canvas, self.parent())
act_save = toolbar._actions['save_figure']
act_copy = QAction(getIcon('edit-copy'), 'Copy', toolbar)
toolbar.insertAction(act_save, act_copy)
# Signals
act_save.triggered.disconnect(toolbar.save_figure)
act_save.triggered.connect(self.save)
act_copy.triggered.connect(self.copy)
return toolbar
示例11: MyMainWindow
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocusPolicy [as 别名]
class MyMainWindow(QMainWindow):
def __init__(self, parent=None):
"""
"""
super(MyMainWindow,self).__init__(parent)
self.setWidgets()
def setWidgets(self, ):
vBox = QVBoxLayout()
mainFrame = QWidget()
self._plotGraphButton = QPushButton("Plot Random Graph")
self._plotGraphButton.clicked.connect(self.plotRandom)
self._fig = figure(facecolor="white")
self._ax = self._fig.add_subplot(111)
self._canvas = FigureCanvas(self._fig)
self._canvas.setParent(mainFrame)
self._canvas.setFocusPolicy(Qt.StrongFocus)
vBox.addWidget(self._plotGraphButton)
vBox.addWidget(self._canvas)
# vBox.addWidget(NavigationToolbar(self._canvas,mainFrame))
mainFrame.setLayout(vBox)
self.setCentralWidget(mainFrame)
def plotRandom(self, ):
"""
"""
x = linspace(0,4*pi,1000)
self._ax.plot(x,sin(2*pi*rand()*2*x),lw=2)
self._canvas.draw()
x,y=np.mgrid[-2:2:20j,-2:2:20j]
z=x*np.exp(-x**2-y**2)
self._ax.plot.subplot(111,projection='3d')
self.plot_surface(x,y,z,rstride=2,cstride=1,cmap=plt.cm.coolwarm,alpha=0.8)
self.ax.set_xlabel('x')
self.ax.set_ylabel('y')
self.ax.set_zlabel('z')
示例12: GraphViewer
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocusPolicy [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')
示例13: MatplotFrame
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocusPolicy [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()
示例14: AppForm
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocusPolicy [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)
示例15: ApplicationWindow
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setFocusPolicy [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)