本文整理汇总了Python中matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg.mpl_connect方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasQTAgg.mpl_connect方法的具体用法?Python FigureCanvasQTAgg.mpl_connect怎么用?Python FigureCanvasQTAgg.mpl_connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg
的用法示例。
在下文中一共展示了FigureCanvasQTAgg.mpl_connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ApplicationWindow
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import mpl_connect [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)
示例2: PlotWindow
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import mpl_connect [as 别名]
class PlotWindow(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
self.setWindowTitle('Online plot')
self.create_main_frame()
self.on_draw()
def save_plot(self):
pass
def on_about(self):
pass
def on_pick(self, event):
pass
def on_draw(self):
self.axes.clear()
self.axes.grid(True)
self.canvas.draw()
def create_main_frame(self):
self.main_frame = QWidget()
self.dpi = 100
self.fig = Figure((20.0, 6.0), dpi=self.dpi)
self.canvas = FigureCanvas(self.fig)
self.canvas.setParent(self.main_frame)
self.axes = self.fig.add_subplot(111)
self.canvas.mpl_connect('pick_event', self.on_pick)
self.mpl_toolbar = NavigationToolbar(self.canvas, self.main_frame)
vbox = QVBoxLayout()
vbox.addWidget(self.canvas)
vbox.addWidget(self.mpl_toolbar)
self.main_frame.setLayout(vbox)
self.setCentralWidget(self.main_frame)
示例3: LsstCatalogPlot
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import mpl_connect [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()
示例4: r_rep_widget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import mpl_connect [as 别名]
def r_rep_widget(self):
"""
This class creates the figure and instance of the ReducedRepPlot that is used to create the plot in the
top right corner
Parameters
----------
self
Returns
-------
None
"""
fig = plt.figure()
canvas = FigureCanvas(fig)
canvas.mpl_connect('button_press_event', self.click_handling)
FigureCanvas.setSizePolicy(canvas, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(canvas)
self.rpp_list.append(ReducedRepPlot(self.data_dict, self.key_list, fig, canvas, self.func_dict))
toolbar = NavigationToolBar(canvas, self)
layout = QtGui.QVBoxLayout()
layout.addWidget(toolbar)
layout.addWidget(canvas)
multi = QtGui.QWidget()
multi.setLayout(layout)
self.plot_dock.setWidget(multi)
示例5: r_rep_widget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import mpl_connect [as 别名]
def r_rep_widget(self):
"""
This class creates the figure and instance of the ReducedRepPlot that is used to create the plot in the
top right corner
Parameters
----------
self
Returns
-------
None
"""
figure = plt.figure()
canvas = FigureCanvas(figure)
canvas.mpl_connect('button_press_event', self.click_handling)
FigureCanvas.setSizePolicy(canvas, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(canvas)
canvas.setMinimumWidth(800)
self.rpp = ReducedRepPlot(self.data_dict, self.key_list, 0, 100, 0, 100, "min", figure, canvas)
toolbar = NavigationToolBar(canvas, self)
layout = QtGui.QVBoxLayout()
layout.addWidget(toolbar)
layout.addWidget(canvas)
self.display_box_1.addStretch()
self.display_box_1.addLayout(layout)
示例6: peak_plot
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import mpl_connect [as 别名]
def peak_plot(self):
"""
This method creates a plot that allows the user to see the x location of all major peaks found in the integrated
data
Parameters
----------
self
Returns
-------
None
"""
window = QtGui.QDialog(self)
window.setWindowTitle('Peak Locations')
window.setWindowModality(QtCore.Qt.NonModal)
fig = plt.figure()
canvas = FigureCanvas(fig)
toolbar = NavigationToolBar(canvas, self)
canvas.mpl_connect('button_press_event', self.click_handling)
peak_graph = PeakPlot(fig, canvas, self.int_data_dict, self.int_key_list)
self.peak_plots.append(peak_graph)
peak_graph.get_plot()
layout = QtGui.QVBoxLayout()
layout.addWidget(toolbar)
layout.addWidget(canvas)
window.setLayout(layout)
window.show()
window.exec_()
示例7: ClusteringConfig
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import mpl_connect [as 别名]
class ClusteringConfig(QDialog):
def __init__(self, parent=None):
QDialog.__init__(self)
self.parent = parent
self.g = self.parent.matplot_frame.g
self.setWindowTitle('Clustering Configuration')
#MPL figure
self.dpi = 100
self.fig = Figure((5.0, 4.0), dpi=self.dpi)
self.fig.subplots_adjust(left=0,right=1,top=1,bottom=0)
#QT canvas
self.canvas = FigureCanvas(self.fig)
self.canvas.setParent(self)
self.canvas.mpl_connect('pick_event', self.on_pick) #used when selecting canvas objects
self.canvas.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
self.axes = self.fig.add_subplot(111)
self.axes.hold(False) #clear the axes every time plot() is called
#MPL Toolbar
self.mpl_toolbar = NavigationToolbar(self.canvas, self)
vbox=QVBoxLayout(self)
vbox.addWidget(self.mpl_toolbar)
vbox.addWidget(self.canvas)
self.setLayout(vbox)
self.resize(650,350)
def on_pick(self):
print 'picked in clustering config'
def _show(self):
self.axes.clear()
self.g = self.parent.matplot_frame.g
self.axes.plot([x[1] for x in self.g.mag], 'o-')
i = 0
v = 45
for x in self.g.mag:
self.axes.annotate(str(self.g.ind[i]), xy=(i, x[1]), xycoords='data',
xytext=(0, v), textcoords='offset points',
arrowprops=dict(arrowstyle="->",
connectionstyle="angle3,angleA=0,angleB=-90"),
)
if v == 15:
v = 45
else:
v -= 15
i += 1
self.show()
示例8: Main
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import mpl_connect [as 别名]
class Main(QMainWindow, Ui_MainWindow) :
def __init__(self, ) :
super(Main, self).__init__()
self.setupUi(self)
self.thisDir = os.path.dirname(os.path.abspath(__file__))
self.btOpenImage.clicked.connect(self.openImage)
fig = Figure()
self.canvas = FigureCanvas(fig)
self.canvasGraph.addWidget(self.canvas)
self.canvas.draw()
return
def openImage(self) :
texto = 'Escolha uma imagem'
path = QtGui.QFileDialog.getOpenFileNameAndFilter(self,
texto,
self.thisDir,
"Images (*.png *.jpg)")
datafile = cbook.get_sample_data(str(path[0]))
img = imread(datafile)
self.updateCanvas(self.initializeCanvas(img))
return
def initializeCanvas(self, img) :
fig = Figure()
fig.clear()
Graph = fig.add_subplot(111)
Graph.imshow(img, zorder=0, extent=[0.0, 1.0, 0.0, 1.0])
return fig
def updateCanvas(self, fig) :
self.canvasGraph.removeWidget(self.canvas)
self.canvas.close()
self.canvas = FigureCanvas(fig)
self.canvasGraph.addWidget(self.canvas)
self.canvas.draw()
def onclick(event):
x, y = event.xdata, event.ydata
print x, y
self.canvas.mpl_connect('button_press_event', onclick)
return
示例9: getWindow
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import mpl_connect [as 别名]
def getWindow(pressfun = pressed):
aw = MyWindow()
vbox = QtGui.QVBoxLayout()
figc = FigureCanvas(Figure())
vbox.addWidget(figc)
f = figc.figure
ax = f.add_axes([0,0,1,1],xlim = [0,10],ylim=[0,10])
ax.plot(range(10))
aw.main_widget.setLayout(vbox)
print 'setting pressfun'
figc.mpl_connect('button_press_event',pressfun)
return aw
示例10: crearWidget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import mpl_connect [as 别名]
def crearWidget(self, filtro, ep):
fig10, fig11 = self.creaFiguras(filtro.tiempo, filtro.temp, filtro.flujo)
canvas1 = FigureCanvas(fig10)
canvas2 = FigureCanvas(fig11)
vbox = QtGui.QGridLayout()
vbox.addWidget(QtGui.QLabel("<b>Episodio:</b> " + filtro.nombre))
vbox.addWidget(QtGui.QLabel("<b>Inicio:</b> " + str(filtro.tiempo[0])))
vbox.addWidget(QtGui.QLabel("<b>Final:</b> " + str(filtro.tiempo[-1])))
vbox.addWidget(QtGui.QLabel("<b>Duración:</b> %i min" % (len(filtro.tiempo))))
vbox.addWidget(QtGui.QLabel("<b>Coeficiente de correlación:</b> " + str(filtro.correlacion)[:5]))
vbox.addWidget(QtGui.QLabel("<b>Calorías consumidas:</b> " + str(filtro.numCalorias)[:6] + " (" + str(filtro.numCalorias/self.selep.totalCal*100)[:4] + "%)"))
vbox.addWidget(canvas1)
vbox.addWidget(canvas2)
canvas2.mpl_connect('pick_event', lambda event: self.onpick(event, ep))
return vbox
示例11: new_r_rep
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import mpl_connect [as 别名]
def new_r_rep(self, selection, x_min, x_max, y_min, y_max):
"""This method will make a reduced representation graph in a new window
Parameters
----------
selection : str
The name of the desired analysis function
x_min : int
the starting x value defined by the ROI
x_max : int
the stopping x value defined by the ROI
y_min : int
the starting y value defined by the ROI
y_max : int
the stopping y value defined by the ROI
Returns
-------
None
"""
try:
popup_window = QtGui.QDialog(self)
popup_window.setWindowTitle(selection)
popup_window.setWindowModality(QtCore.Qt.NonModal)
fig = plt.figure()
canvas = FigureCanvas(fig)
canvas.mpl_connect('button_press_event', self.click_handling)
toolbar = NavigationToolBar(canvas, self)
self.rpp_list.append(ReducedRepPlot(self.data_dict, self.key_list, fig, canvas, self.func_dict, selection))
idx = len(self.rpp_list) - 1
vbox = QtGui.QVBoxLayout()
vbox.addStretch()
vbox.addWidget(toolbar)
vbox.addStretch()
vbox.addWidget(canvas)
popup_window.setLayout(vbox)
popup_window.show()
self.rpp_list[idx].x_start = x_min
self.rpp_list[idx].x_stop = x_max
self.rpp_list[idx].y_start = y_min
self.rpp_list[idx].y_stop = y_max
self.rpp_list[idx].show()
popup_window.exec_()
except Exception:
print("error creating a new rpp window")
finally:
self.rpp_list.__delitem__(idx)
示例12: MatplotlibWidget
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import mpl_connect [as 别名]
class MatplotlibWidget(QWidget):
def __init__(self,parent=None,grid=True):
QWidget.__init__(self,parent)
self.grid = grid
self.fig = Figure()
self.canvas =FigureCanvas(self.fig)
self.canvas.setParent(self)
self.canvas.mpl_connect('button_press_event', self.onPick) # bind pick event
#self.axes = self.fig.add_subplot(111)
margins = [0.05,0.1,0.9,0.8]
self.axes = self.fig.add_axes(margins)
self.toolbar = NavigationToolbar(self.canvas,self)
#self.initFigure()
layout = QVBoxLayout()
layout.addWidget(self.toolbar)
layout.addWidget(self.canvas)
self.setLayout(layout)
def onPick(self,event):
print 'Pick event'
print 'you pressed', event.button, event.xdata, event.ydata
def update(self):
self.canvas.draw()
def plot(self,*args,**kwargs):
self.axes.plot(*args,**kwargs)
self.axes.grid(self.grid)
self.update()
def clear(self):
self.axes.clear()
def initFigure(self):
self.axes.grid(True)
x = np.linspace(-1,1)
y = x**2
self.axes.plot(x,y,'o-')
示例13: GraphViewer
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import mpl_connect [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')
示例14: __crearBarWidget__
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import mpl_connect [as 别名]
def __crearBarWidget__(self, means):
def onpick(event):
rect = event.artist
for i in range(len(self.bar)): # MEJORAR!!
if self.bar[i] == rect:
print "Barra", self.selep.epFiltro[i].nombre, self.selep.epFiltro[i].numCalorias, "calorías", len(
self.selep.epFiltro[i].tiempo
), "minutos"
lbl = (
"("
+ self.selep.epFiltro[i].nombre
+ ") "
+ str(self.selep.epFiltro[i].numCalorias)[:6]
+ " calorías "
+ str(len(self.selep.epFiltro[i].tiempo))
+ " minutos"
)
self.lblDetalles.setText(lbl)
return
fig = plt.figure(facecolor="white")
ax = fig.add_subplot(111)
colors = []
for i in self.selep.epFiltro:
if i.tipo == cachitos.tipoSueno:
c = colores.sueno
elif i.tipo == cachitos.tipoSedentario:
c = colores.sedentario
elif i.tipo == cachitos.tipoLigera:
c = colores.ligero
elif i.tipo == cachitos.tipoModerado:
c = colores.moderado
colors.append(c)
ind = np.linspace(10, len(means), num=len(means))
self.bar = ax.bar(ind, means, color=colors, picker=1, align="center")
ax.set_xticklabels(np.arange(len(means)))
fig.tight_layout()
canvas = FigureCanvas(fig)
vbox = QtGui.QGridLayout()
vbox.addWidget(canvas)
canvas.mpl_connect("pick_event", onpick)
# return FigureCanvas(fig)
return vbox
示例15: Plot
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import mpl_connect [as 别名]
class Plot():
def __init__(self, parent=None, width=5, height=5, dpi=100):
#pl.ion()
self.fig = Figure(figsize=(width, height), dpi=dpi)
self.canvas = FigureCanvas(self.fig)
self.canvas.setParent(parent)
self.canvas.mpl_connect('button_press_event', self.on_click)
self.rho_area = self.fig.add_subplot(111)
#プロットエリアがクリックされた時
def on_click(self, event):
print 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f'%(
event.button, event.x, event.y, event.xdata, event.ydata)
row = int(event.ydata)
col = int(event.xdata)
print 'cca r:',self.r_m[row][col]
def on_draw(self, r):
self.r_m = r
self.rho_area = self.fig.add_subplot(111)
fs = 10
dr, dc = self.r_m.shape
Y, X = np.mgrid[slice(0, dr+1, 1),slice(0, dc+1, 1)]
img = self.rho_area.pcolor(X, Y, self.r_m, vmin=0.0, vmax=1.0, cmap=cm.gray)
"""
if self.cbar == None:
self.cbar = self.fig.colorbar(img)
self.cbar.ax.tick_params(labelsize=fs-1)
"""
self.rho_area.set_xlim(0, dc)
self.rho_area.set_ylim(0, dr)
wid = 10 #とりあえず決め打ちで10ずつ目盛表示
ticks = [i*wid for i in range(dr/wid+1)]
labels = [(dr-1)/2-i*wid for i in range(dr/wid+1)]
self.rho_area.set_yticks(ticks=ticks)
self.rho_area.set_yticklabels(labels=labels)
self.rho_area.set_xlabel("user 1")
self.rho_area.set_ylabel("user 2")
self.rho_area.tick_params(labelsize=fs)
self.rho_area.set_title("rho", fontsize=fs+1)
self.fig.canvas.draw()