本文整理汇总了Python中matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg.underMouse方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasQTAgg.underMouse方法的具体用法?Python FigureCanvasQTAgg.underMouse怎么用?Python FigureCanvasQTAgg.underMouse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg
的用法示例。
在下文中一共展示了FigureCanvasQTAgg.underMouse方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GUI
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import underMouse [as 别名]
#.........这里部分代码省略.........
# DEFAULT FUNCTION FOR KEY AND MOUSE PRESS ON WINDOW
#-----------------------------------------------------------------------------------------------
def keyPressEvent(self, event):
# print(event.key())
# change timepoint
if event.key() == QtCore.Qt.Key_Right:
self.changeSpaceTime( 'time', +1 )
elif event.key() == QtCore.Qt.Key_Left:
self.changeSpaceTime( 'time', -1 )
# change slice
elif event.key() == QtCore.Qt.Key_Up:
self.changeSpaceTime( 'space', +1 )
elif event.key() == QtCore.Qt.Key_Down:
self.changeSpaceTime( 'space', -1 )
elif event.key() == QtCore.Qt.Key_Space:
if len( self.currentCells ) > 0:
idx = np.mod( self.currentCells.ix[ self.currentCells.cname == self.analyzedCell ].index + 1, len(self.currentCells) )
self.analyzedCell = self.currentCells.cname.values[idx][0]
self.sl.setValue( self.currentCells.ix[ self.currentCells.cname == self.analyzedCell, 'Z' ] )
self.updateAllCanvas()
self.setFocus()
def wheelEvent(self,event):
if self.canvas1.underMouse():
step = event.step
else:
step = event.delta()/abs(event.delta())
self.sl.setValue( self.sl.value() + step)
#-----------------------------------------------------------------------------------------------
# ADDITIONAL FUNCTIONS FOR KEY AND MOUSE PRESS ON CANVASES
#-----------------------------------------------------------------------------------------------
def onMouseClickOnCanvas1(self, event):
pos = np.array( [ int(event.xdata), int(event.ydata) ] )
outline = extract_out( self.currentCells.ix[ self.currentCells.cname == self.analyzedCell ].squeeze() )
if event.button == 1:
if np.isnan( outline[0,0] ):
outline = np.array( [ pos ] )
else:
outline = np.vstack( [ outline, pos ] )
elif event.button == 3:
if len( outline[ :, 0 ] ) == 1:
outline = np.array( [ [ np.nan, np.nan ] ] )
else:
outline = outline[:-1,:]
idx = self.currentCells.ix[ self.currentCells.cname == self.analyzedCell ].index
self.currentCells.Xout.values[ idx ] = [ outline[:,0] ]
示例2: GUI
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import underMouse [as 别名]
#.........这里部分代码省略.........
def updateAllCanvas(self):
self.updateRadioBtn()
self.updateCanvas1()
def radioClicked(self):
if self._488nmBtn.isChecked():
if '488nm' in self.channels.keys():
self.currentChannel = '488nm'
else:
QtGui.QMessageBox.about(self, 'Warning', 'No 488nm channel!')
elif self._561nmBtn.isChecked():
if '561nm' in self.channels.keys():
self.currentChannel = '561nm'
else:
QtGui.QMessageBox.about(self, 'Warning', 'No 561nm channel!')
elif self.CoolLEDBtn.isChecked():
if 'CoolLED' in self.channels.keys():
self.currentChannel = 'CoolLED'
else:
QtGui.QMessageBox.about(self, 'Warning', 'No CoolLED channel!')
self.setBCslidersMinMax()
self.resetBC()
self.setFocus()
self.updateAllCanvas()
def keyPressEvent(self, event):
# key press on cropped image
if self.canvas1.underMouse():
self.onKeyPressOnCanvas1(event)
self.setFocus()
#-----------------------------------------------------------------------------------------------
# DEFAULT FUNCTION FOR KEY AND MOUSE PRESS ON WINDOW
#-----------------------------------------------------------------------------------------------
def wheelEvent(self,event):
if self.canvas1.underMouse():
step = event.step
else:
step = event.delta()/abs(event.delta())
### update daytaframe with previously labeled cells
newapdvDF = update_apdv_pos_DF( self.currentPos, self.apdvPosDF, self.tp.value() )
self.apdvPosDF = newapdvDF
print(self.currentPos) # print previously labeled positions
### extract current cells already labeled
self.currentPos = extract_current_apdv_pos( self.apdvPosDF, self.tp.value() + step )
self.tp.setValue( self.tp.value() + step )
self.fName.setText( self.timesDF.ix[ self.timesDF.tidxRel == self.tp.value(), 'fName' ].values[0] )
#-----------------------------------------------------------------------------------------------
# ADDITIONAL FUNCTIONS FOR KEY AND MOUSE PRESS ON CANVASES
#-----------------------------------------------------------------------------------------------
示例3: GUI
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import underMouse [as 别名]
#.........这里部分代码省略.........
# DEFAULT FUNCTION FOR KEY AND MOUSE PRESS ON WINDOW
#-----------------------------------------------------------------------------------------------
def keyPressEvent(self, event):
# print(event.key())
# change timepoint
if event.key() == QtCore.Qt.Key_Right:
self.changeSpaceTime( 'time', +1 )
elif event.key() == QtCore.Qt.Key_Left:
self.changeSpaceTime( 'time', -1 )
# change slice
elif event.key() == QtCore.Qt.Key_Up:
self.changeSpaceTime( 'space', +1 )
elif event.key() == QtCore.Qt.Key_Down:
self.changeSpaceTime( 'space', -1 )
elif event.key() == QtCore.Qt.Key_Space:
if len( self.currentCells ) > 0:
idx = np.mod( self.currentCells.ix[ self.currentCells.cname == self.analyzedCell ].index + 1, len(self.currentCells) )
self.analyzedCell = self.currentCells.cname.values[idx][0]
self.sl.setValue( self.currentCells.ix[ self.currentCells.cname == self.analyzedCell, 'Z' ] )
self.updateAllCanvas()
self.setFocus()
def wheelEvent(self,event):
if self.canvas1.underMouse():
step = event.step
else:
step = event.delta()/abs(event.delta())
self.sl.setValue( self.sl.value() + step)
#-----------------------------------------------------------------------------------------------
# ADDITIONAL FUNCTIONS FOR KEY AND MOUSE PRESS ON CANVASES
#-----------------------------------------------------------------------------------------------
def onMouseClickOnCanvas1(self, event):
if self._488nmBtn.isChecked():
channel = '488nm'
elif self._561nmBtn.isChecked():
channel = '561nm'
else:
QtGui.QMessageBox.about(self, 'Warning', 'Select a proper fluorescence channel!')
return
currentCell = self.currentCells.ix[ self.currentCells.cname == self.analyzedCell ].squeeze()
imgpxl = currentCell.imgPxl
cell = self.currentCells.ix[ self.currentCells.cname == self.analyzedCell ].squeeze()
cellPos = extract_3Dpos( cell )
cellOut = extract_out( cell ) * imgpxl / 1000.
# calculate new drift
pos = np.array( [ int(np.round(event.xdata)), int(np.round(event.ydata)) ] )
drift = np.array([pos[0]-500,pos[1]-500]) * self.imgpxl / 1000.
### perform flat field correction
# find gonadpos
gonadPos = extract_pos( self.gpDF.ix[ self.gpDF.tidx == self.tp.value() ].squeeze() )
# load darkField
示例4: GUI
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import underMouse [as 别名]
#.........这里部分代码省略.........
#-----------------------------------------------------------------------------------------------
# DEFAULT FUNCTION FOR KEY AND MOUSE PRESS ON WINDOW
#-----------------------------------------------------------------------------------------------
def keyPressEvent(self, event):
# print(event.key())
# change timepoint
if event.key() == QtCore.Qt.Key_Right:
self.changeSpaceTime( 'time', +1 )
elif event.key() == QtCore.Qt.Key_Left:
self.changeSpaceTime( 'time', -1 )
# change slice
elif event.key() == QtCore.Qt.Key_Up:
self.changeSpaceTime( 'space', +1 )
elif event.key() == QtCore.Qt.Key_Down:
self.changeSpaceTime( 'space', -1 )
elif event.key() == QtCore.Qt.Key_Space:
idx = self.channels.index(self.currentChannel)
if self.channels[ (idx+1)%len(self.channels) ] == 'CoolLED':
self.CoolLEDBtn.setChecked(True)
if self.channels[ (idx+1)%len(self.channels) ] == '488nm':
self._488nmBtn.setChecked(True)
if self.channels[ (idx+1)%len(self.channels) ] == '561nm':
self._561nmBtn.setChecked(True)
# key press on cropped image
if self.canvas1.underMouse():
self.onKeyPressOnCanvas1(event)
self.setFocus()
def wheelEvent(self,event):
if self.canvas1.underMouse():
step = event.step
else:
step = event.delta()/abs(event.delta())
self.sl.setValue( self.sl.value() + step)
#-----------------------------------------------------------------------------------------------
# ADDITIONAL FUNCTIONS FOR KEY AND MOUSE PRESS ON CANVASES
#-----------------------------------------------------------------------------------------------
def onKeyPressOnCanvas1(self, event):
motherCells = [ QtCore.Qt.Key_1, QtCore.Qt.Key_4, QtCore.Qt.Key_B ]
daughterCells = [ QtCore.Qt.Key_A, QtCore.Qt.Key_P ]
# find the position of the cursor relative to the image in pixel
imgshape = self.stacks[self.currentChannel][self.sl.value()].shape
canshape = self.canvas1.size()
cf = imgshape[0]/canshape.width()
refpos = self.canvas1.mapFromGlobal(QtGui.QCursor.pos())
refpos = np.array([ int( refpos.x() * cf ), int( refpos.y() * cf )])
refpos = np.append(refpos,self.sl.value())
### find the closest cell to the cursor
idx = closer_cell( refpos.astype( np.uint16 ), self.currentCells )
### assign the name to the cell
示例5: GUI
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import underMouse [as 别名]
#.........这里部分代码省略.........
# DEFAULT FUNCTION FOR KEY AND MOUSE PRESS ON WINDOW
#-----------------------------------------------------------------------------------------------
def keyPressEvent(self, event):
# print(event.key())
# change timepoint
if event.key() == QtCore.Qt.Key_Right:
self.changeSpaceTime( 'time', +1 )
elif event.key() == QtCore.Qt.Key_Left:
self.changeSpaceTime( 'time', -1 )
# change slice
elif event.key() == QtCore.Qt.Key_Up:
self.changeSpaceTime( 'space', +1 )
elif event.key() == QtCore.Qt.Key_Down:
self.changeSpaceTime( 'space', -1 )
elif event.key() == QtCore.Qt.Key_Space:
if len( self.currentCells ) > 0:
idx = np.mod( self.currentCells.ix[ self.currentCells.cname == self.analyzedCell ].index + 1, len(self.currentCells) )
self.analyzedCell = self.currentCells.cname.values[idx][0]
self.sl.setValue( self.currentCells.ix[ self.currentCells.cname == self.analyzedCell, 'Z' ] )
self.updateAllCanvas()
self.setFocus()
def wheelEvent(self,event):
if self.canvas1.underMouse():
step = event.step
else:
step = event.delta()/abs(event.delta())
self.sl.setValue( self.sl.value() + step)
#-----------------------------------------------------------------------------------------------
# ADDITIONAL FUNCTIONS FOR KEY AND MOUSE PRESS ON CANVASES
#-----------------------------------------------------------------------------------------------
def onMouseClickOnCanvas1(self, event):
pos = np.array( [ int(np.round(event.xdata)), int(np.round(event.ydata)) ] )
outline = extract_out( self.currentCells.ix[ self.currentCells.cname == self.analyzedCell ].squeeze() )
if event.button == 1:
if np.isnan( outline[0,0] ):
outline = np.array( [ pos ] )
else:
outline = np.vstack( [ outline, pos ] )
elif event.button == 3:
if len( outline[ :, 0 ] ) == 1:
outline = np.array( [ [ np.nan, np.nan ] ] )
else:
outline = outline[:-1,:]
idx = self.currentCells.ix[ self.currentCells.cname == self.analyzedCell ].index
self.currentCells.Xout.values[ idx ] = [ outline[:,0] ]
示例6: GUI
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import underMouse [as 别名]
#.........这里部分代码省略.........
#-----------------------------------------------------------------------------------------------
# DEFAULT FUNCTION FOR KEY AND MOUSE PRESS ON WINDOW
#-----------------------------------------------------------------------------------------------
def keyPressEvent(self, event):
# print(event.key())
# change timepoint
if event.key() == QtCore.Qt.Key_Right:
self.changeSpaceTime( self.tp, +1 )
if event.key() == QtCore.Qt.Key_Left:
self.changeSpaceTime( self.tp, -1 )
# change slice
if event.key() == QtCore.Qt.Key_Up:
self.changeSpaceTime( self.sl, +1 )
if event.key() == QtCore.Qt.Key_Down:
self.changeSpaceTime( self.sl, -1 )
# change channel
if event.key() == QtCore.Qt.Key_Space:
currentidx = list(self.fList.keys()).index(self.channel)
nextidx = np.mod(currentidx+1,len(self.fList.keys()))
self.channel = list(self.fList.keys())[nextidx]
self.setBCslidersMinMax()
self.resetBC()
self.updateAllCanvas()
# key press on straighten worm
if self.canvas2.underMouse():
self.onKeyPressOnCanvas2(event)
self.setFocus()
def wheelEvent(self,event):
if any([ self.canvas1.underMouse(), self.canvas2.underMouse(), self.canvas3.underMouse() ]):
step = event.step
else:
step = event.delta()/abs(event.delta())
self.sl.setValue( self.sl.value() + step)
#-----------------------------------------------------------------------------------------------
# ADDITIONAL FUNCTIONS FOR KEY AND MOUSE PRESS ON CANVASES
#-----------------------------------------------------------------------------------------------
def onKeyPressOnCanvas2(self, event):
# print(event.key())
cellsname = [ QtCore.Qt.Key_A, QtCore.Qt.Key_B, QtCore.Qt.Key_C, QtCore.Qt.Key_1,
QtCore.Qt.Key_2, QtCore.Qt.Key_3, QtCore.Qt.Key_4, QtCore.Qt.Key_5,
QtCore.Qt.Key_6, QtCore.Qt.Key_T ]
cellspos = [ QtCore.Qt.Key_Q, QtCore.Qt.Key_W ]
# find the position of the cursor relative to the image in pixel
imgshape = self.stacksStraight[self.channel][self.sl.value()].shape
arimg = imgshape[1]/imgshape[0]
canshape = self.canvas2.size()
arcan = canshape.width()/canshape.height()
cf = 1
if arimg>arcan:
cf = imgshape[1]/canshape.width()
示例7: GUI
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import underMouse [as 别名]
#.........这里部分代码省略.........
if enabled:
if '561nm' in self.channels:
self.currentChannel = '561nm'
self.setFocus()
self.updateCanvas1()
else:
if self.currentChannel == 'CoolLED':
self.CoolLEDBtn.setChecked(True) # this uppdates the canvas1 once more
elif self.currentChannel == '488nm':
self._488nmBtn.setChecked(True) # this uppdates the canvas1 once more
QtGui.QMessageBox.about(self, 'Warning', 'No 561nm channel!')
def radioCoolLEDClicked(self, enabled):
# print('radio LED clicked')
if enabled:
if 'CoolLED' in self.channels:
self.currentChannel = 'CoolLED'
self.setFocus()
self.updateCanvas1()
else:
if self.currentChannel == '561nm':
self._561nmBtn.setChecked(True) # this uppdates the canvas1 once more
elif self.currentChannel == '488nm':
self._488nmBtn.setChecked(True) # this uppdates the canvas1 once more
QtGui.QMessageBox.about(self, 'Warning', 'No CoolLED channel!')
#-----------------------------------------------------------------------------------------------
# DEFAULT FUNCTION FOR KEY AND MOUSE PRESS ON WINDOW
#-----------------------------------------------------------------------------------------------
def wheelEvent(self,event):
if self.canvas1.underMouse():
step = event.step
else:
step = event.delta()/abs(event.delta())
self.tp.setValue( self.tp.value() + step )
self.fName.setText( self.timesDF.ix[ self.timesDF.tidxRel == self.tp.value(), 'fName' ].values[0] )
#-----------------------------------------------------------------------------------------------
# ADDITIONAL FUNCTIONS FOR KEY AND MOUSE PRESS ON CANVASES
#-----------------------------------------------------------------------------------------------
def onMouseClickOnCanvas1(self, event):
# print(event.button,event.xdata,event.ydata)
x = event.xdata
y = event.ydata
if event.button == 1:
# left button: add a point to the outline
gonadPos = ( np.array( [ x, y ] ) * self.compression ).astype( np.uint16 )
if event.button == 3:
gonadPos = [ np.nan, np.nan ]
# update the dataframe with the new gonadPos
self.gpDF.ix[ self.gpDF.tidx == self.tp.value(), 'X' ] = gonadPos[0]
self.gpDF.ix[ self.gpDF.tidx == self.tp.value(), 'Y' ] = gonadPos[1]
示例8: GUI
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import underMouse [as 别名]
#.........这里部分代码省略.........
elif self.CoolLEDBtn.isChecked():
if 'CoolLED' in self.channels:
self.currentChannel = 'CoolLED'
else:
QtGui.QMessageBox.about(self, 'Warning', 'No CoolLED channel!')
self.setBCslidersMinMax()
self.resetBC()
self.setFocus()
self.updateAllCanvas()
#-----------------------------------------------------------------------------------------------
# DEFAULT FUNCTION FOR KEY AND MOUSE PRESS ON WINDOW
#-----------------------------------------------------------------------------------------------
def keyPressEvent(self, event):
# print(event.key())
# change timepoint
if event.key() == QtCore.Qt.Key_Right:
self.changeSpaceTime( 'time', +1 )
elif event.key() == QtCore.Qt.Key_Left:
self.changeSpaceTime( 'time', -1 )
# change slice
elif event.key() == QtCore.Qt.Key_Up:
self.changeSpaceTime( 'space', +1 )
elif event.key() == QtCore.Qt.Key_Down:
self.changeSpaceTime( 'space', -1 )
# key press on cropped image
if self.canvas1.underMouse():
self.onKeyPressOnCanvas1(event)
self.setFocus()
def wheelEvent(self,event):
if self.canvas1.underMouse():
step = event.step
else:
step = event.delta()/abs(event.delta())
self.sl.setValue( self.sl.value() + step)
#-----------------------------------------------------------------------------------------------
# ADDITIONAL FUNCTIONS FOR KEY AND MOUSE PRESS ON CANVASES
#-----------------------------------------------------------------------------------------------
def onKeyPressOnCanvas1(self, event):
motherCells = [ QtCore.Qt.Key_1, QtCore.Qt.Key_4, QtCore.Qt.Key_B ]
daughterCells = [ QtCore.Qt.Key_A, QtCore.Qt.Key_P ]
# find the position of the cursor relative to the image in pixel
imgshape = self.stacks[self.currentChannel][self.sl.value()].shape
canshape = self.canvas1.size()
cf = imgshape[0]/canshape.width()
refpos = self.canvas1.mapFromGlobal(QtGui.QCursor.pos())
refpos = np.array([ int( refpos.x() * cf ), int( refpos.y() * cf )])
refpos = np.append(refpos,self.sl.value())
### find the closest cell to the cursor
idx = closer_cell( refpos.astype( np.uint16 ), self.currentCells )
### assign the name to the cell
示例9: GUI
# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import underMouse [as 别名]
#.........这里部分代码省略.........
# DEFAULT FUNCTION FOR KEY AND MOUSE PRESS ON WINDOW
#-----------------------------------------------------------------------------------------------
def keyPressEvent(self, event):
# print(event.key())
# change timepoint
if event.key() == QtCore.Qt.Key_Right:
self.changeSpaceTime( self.tp, +1 )
if event.key() == QtCore.Qt.Key_Left:
self.changeSpaceTime( self.tp, -1 )
# change slice
if event.key() == QtCore.Qt.Key_Up:
self.changeSpaceTime( self.sl, +1 )
if event.key() == QtCore.Qt.Key_Down:
self.changeSpaceTime( self.sl, -1 )
# change channel
if event.key() == QtCore.Qt.Key_Space:
currentidx = list(self.fList.keys()).index(self.channel)
nextidx = np.mod(currentidx+1,len(self.fList.keys()))
self.channel = list(self.fList.keys())[nextidx]
self.setBCslidersMinMax()
self.resetBC()
self.updateAllCanvas()
self.setFocus()
def wheelEvent(self,event):
if self.canvas1.underMouse():
step = event.step
else:
step = event.delta()/abs(event.delta())
self.sl.setValue( self.sl.value() + step)
#-----------------------------------------------------------------------------------------------
# ADDITIONAL FUNCTIONS FOR KEY AND MOUSE PRESS ON CANVASES
#-----------------------------------------------------------------------------------------------
def onMouseClickOnCanvas1(self, event):
# print(event.button,event.xdata,event.ydata)
tp = self.tp.value()
sl = self.sl.value()
rowmask = self.df['rowtype']=='body'
outline = self.df.ix[ rowmask, 'outline' ].values
spline = self.df.ix[ rowmask, 'spline' ].values
x = event.xdata
y = event.ydata
# left button: add a point to the outline
if event.button == 1:
if not np.all(np.isnan(outline[tp])):
idx = find_closest_point( [ x, y ], outline[tp] )
else:
idx = 0
outline[tp] = np.insert( outline[tp], idx+1, [ x, y, sl ], axis=0 )