本文整理汇总了Python中matplotlib.backends.backend_tkagg.FigureCanvasTkAgg.mpl_disconnect方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasTkAgg.mpl_disconnect方法的具体用法?Python FigureCanvasTkAgg.mpl_disconnect怎么用?Python FigureCanvasTkAgg.mpl_disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_tkagg.FigureCanvasTkAgg
的用法示例。
在下文中一共展示了FigureCanvasTkAgg.mpl_disconnect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ImagePanel
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_disconnect [as 别名]
#.........这里部分代码省略.........
self.yp1 = None
self.rectangle = Rectangle((0,0), 1, 1, facecolor='None', edgecolor='green')
self.subplot.add_patch(self.rectangle)
self.ispressed = False
self.bpe = self.canvas.mpl_connect('button_press_event', self.drawRectangle_onPress)
self.bre = self.canvas.mpl_connect('button_release_event', self.drawRectangle_onRelease)
self.mne = self.canvas.mpl_connect('motion_notify_event', self.drawRectangle_onMotion)
def drawRectangle_onPress(self, event):
self.xp0 = event.x
self.yp0 = event.y
self.x0 = event.xdata
self.y0 = event.ydata
self.x1 = event.xdata
self.y1 = event.ydata
self.rectangle.set_width(self.x1-self.x0)
self.rectangle.set_xy((self.x0, self.y0))
self.rectangle.set_linestyle('dashed')
self.canvas.draw()
self.ispressed = True
def drawRectangle_onRelease(self, event):
self.xp1 = event.x
self.yp1 = event.y
self.x1 = event.xdata
self.y1 = event.ydata
self.rectangle.set_width(self.x1-self.x0)
self.rectangle.set_height(self.y1-self.y0)
self.rectangle.set_xy((self.x0, self.y0))
self.rectangle.set_linestyle('solid')
self.canvas.draw()
self.ispressed = False
self.canvas.mpl_disconnect(self.bpe)
self.canvas.mpl_disconnect(self.bre)
self.canvas.mpl_disconnect(self.mne)
print(self.xp0, self.yp0, self.xp1, self.yp1)
self.inform('<DrawRectangle>')
return (self.xp0, self.yp0, self.xp1, self.yp1)
def getRectanglePoints(self):
return (self.xp0, self.yp0, self.xp1, self.yp1)
def drawRectangle_onMotion(self, event):
if self.ispressed is True:
self.x1 = event.xdata
self.y1 = event.ydata
self.rectangle.set_width(self.x1-self.x0)
self.rectangle.set_height(self.y1-self.y0)
self.rectangle.set_xy((self.x0, self.y0))
self.rectangle.set_linestyle('dashed')
self.canvas.draw()
def deleteRectangle(self):
print('Delete rectangle!')
self.rectangle.remove()
self.canvas.draw()
self.inform('<DeleteRectangle>')
def zoomIn(self):
print('Zoom in!')
print(np.shape(self.images))
self.images = self.images[:,10:-10, 10:-10]
self.show_images()
self.nZoom = self.nZoom+1
示例2: PlotWindow
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_disconnect [as 别名]
#.........这里部分代码省略.........
self.main_axes.set_xlabel('')
except:
self.main_axes.set_xlabel('Energy (keV)')
return self.rois_to_energies()
else:
try:
self.bottom_axes.set_xlabel('ROI')
self.main_axes.set_xlabel('')
except:
self.main_axes.set_xlabel('ROI')
return rois_numbers
def mogonio_to_energy(self):
p = self.parameters
energies_values = np.array(self.data[:, p['energy_column']], dtype=float)
if p['use_mogonio_calibration']:
A = p['mogonio_calibration_a']
B = p['mogonio_calibration_b']
hc = 1239.8 # nm.eV
a = 0.543102 # lattice parameter for Si, in nm
miller_indices = [1, 1, 1]
m = miller_indices
return (hc * np.sqrt(m[0]**2 + m[1]**2 + m[2]**2)/(2*a*np.sin(np.radians(A + B*energies_values))))/1000.0
else:
return energies_values
def rois_to_energies(self, fresh=False):
' Used on plots which have ROI as x axis '
p = self.parameters
rois_numbers = self.columns_names_parse_as_int(p['intensity_names'])
# Fitting
if not fresh:
calib = Tools.list_to_numpy(p['calibration_data'])
else:
calib = Tools.list_to_numpy(self.application.widgets['calib_tree'].get_data())
equation_parameters = np.polyfit(calib[:, 1], calib[:, 0], min(2, calib.shape[0]-1))
self.log('* Energy calibration coefficients: ' + str(equation_parameters))
# Apply fitting equation to ROIs numbers
energies = np.polyval(equation_parameters, rois_numbers)
return energies
def action_btn_zoomall(self, *args, **kwargs):
first = True
for line in self.main_axes.lines:
if first:
min_x = min(line.get_xdata())
max_x = max(line.get_xdata())
min_y = min(line.get_ydata())
max_y = max(line.get_ydata())
first = False
else:
min_x = min(min_x, min(line.get_xdata()))
max_x = max(max_x, max(line.get_xdata()))
min_y = min(min_y, min(line.get_ydata()))
max_y = max(max_y, max(line.get_ydata()))
if not first: # If there is at least 1 line
self.main_axes.set_xlim([min_x, max_x])
self.main_axes.set_ylim([min_y, max_y])
# Redraw changes
self.fig.canvas.draw()
def action_btn_normalization(self, *args, **kwargs):
if not self.normalization_flag:
self.normalization_flag = True
self.widgets['btn_normalization']['text'] = 'Please double-click on y=0...'
self.normalization_connection = self.canvas.mpl_connect('button_press_event', self.action_normalization_firstclick)
else:
self.widgets['btn_normalization']['text'] = 'Normalize y-axis'
self.normalization_flag = False
self.canvas.mpl_disconnect(self.normalization_connection)
def action_normalization_firstclick(self, event, *args, **kwargs):
if event.dblclick and event.inaxes == self.main_axes:
y = event.ydata
self.new_base_value = self.base_value + y * self.normalization_value
self.canvas.mpl_disconnect(self.normalization_connection)
self.normalization_connection = self.canvas.mpl_connect('button_press_event', self.action_normalization_secondclick)
self.widgets['btn_normalization']['text'] = 'Please double-click on y=1...'
def action_normalization_secondclick(self, event, *args, **kwargs):
if event.dblclick and event.inaxes == self.main_axes:
y = event.ydata
self.normalization_value = (self.normalization_value * y + self.base_value - self.new_base_value)
self.base_value = self.new_base_value
self.action_btn_normalization()
self.refresh_plot()
def action_btn_derivative(self, *args, **kwargs):
if self.selected_artist is not None:
y = self.selected_artist['artist'].get_ydata()
x = self.selected_artist['artist'].get_xdata()
# Border effects may exist
derivative_data = np.convolve(np.array([-1, 0, 1]), y, mode='same')
delta_data = np.convolve(np.array([-1, 0, 1]), x, mode='same')
derivative_data = np.divide(derivative_data, delta_data)
self.main_axes.plot(x, derivative_data, picker=self.picker_tolerance, label='<Derivative of ' + self.selected_artist['artist'].get_label() + '>')
self.fig.canvas.draw()
示例3: labTOF
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_disconnect [as 别名]
#.........这里部分代码省略.........
self.time_domain()
#set calibration buttons (add new, finish) to enabled state
self.calibrateButton.config(state=NORMAL)
self.finishcalButton.config(state=NORMAL)
#called when "Start New Calibration" is selected in MSMS mode
def onMSMSCalStart(self):
#sets MSMS flag for finish_calibrate routine
self.MSMS_flag=1
#reset calibration points
self.cal_time=[]
self.cal_mass=[]
#plot data in time domain (reset plot)
self.time_domain()
#set calibration button (ID parent peak, finish) to enabled state
self.parentButton.config(state=NORMAL)
self.finishcalButton.config(state=NORMAL)
#called when click is made in plotting environment during calibration
def on_click(self, event):
temp_len=len(self.cal_time)
#when the click is made within the plotting window
if event.inaxes is not None:
#print 'clicked: ', event.xdata, event.ydata
self.cal_time.append(event.xdata*1E-6)
#sets up dialog box for user to enter mass value
self.MassDialog(self.parent)
#if click is outside plotting window
else:
print 'Clicked ouside axes bounds but inside plot window'
#disconnect from calibration click event when a new calibration value is set
if len(self.cal_time) > temp_len:
self.canvas.mpl_disconnect(self.cid)
#called during calibration
#asks user for mass value associated with time value selected
def MassDialog(self, parent):
top = self.top = Toplevel(self.parent)
Label(top, text="Actual Mass Value:").pack()
self.e=Entry(top)
self.e.pack(padx=5)
#calls DialogOK to set mass value to input
b=Button(top, text="OK", command=self.DialogOK)
b.pack(pady=5)
#called when Smooth button is pressed
#asks user for smooth input data
def SmoothDialog(self, parent):
top = self.top = Toplevel(self.parent)
#window length for smoothing function
#must be greater than poly value, positive, odd (51)
Label(top, text="Window Length:").grid(row=0, column=0, sticky=W, padx=5, pady=5)
self.w=Entry(top)
self.w.grid(row=0, column=1, padx=5, pady=5)
#polynomial order
#must be less than window length (3)
Label(top, text="Polynomial Order:").grid(row=1, column=0, sticky=W, padx=5, pady=5)
self.p=Entry(top)
self.p.grid(row=1, column=1, padx=5, pady=5)
#calls DialogSmoothOK to set these values
b=Button(top, text="OK", command=self.DialogSmoothOK)
b.grid(row=2, column=1, padx=5, pady=5)
示例4: __init__
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_disconnect [as 别名]
#.........这里部分代码省略.........
#Update CT.AX1, perserve the x-axis bounds, and return to original y-axis
self.ax1.set_ylim(ymin,ymax)
self.ax1.set_xlim(xmin,xmax)
#Update CT.AX2 by plotting new spline, also perserve the x-axis bounds
self.ax2.plot(self.iwvlngth,self.ispectrum,'k',drawstyle='steps')
self.ax2.plot(xcont,ycont,'b')
self.ax2.plot(self.xspline,self.yspline,'or',picker=5)
self.ax2.set_ylabel('Flux\n(tweaked fit)')
self.ax2.set_ylim(ymin,ymax)
self.ax2.set_xlim(xmin,xmax)
#in CT.AX2, Divide out the spectrum&errorspectrum by the continuum, and plot
self.ax3.plot(xcont,self.ispectrum/ycont,'k',drawstyle='steps')
self.ax3.plot(xcont,1.0-self.espectrum/ycont,'--g',drawstyle='steps')
self.ax3.plot(xcont,1.0+self.espectrum/ycont,'--g',drawstyle='steps')
self.ax3.set_ylabel('Relative flux')
self.ax3.set_xlabel('Wavlength')
self.ax3.set_ylim(-1,2)
self.ax3.plot([self.xmin,self.xmax],[1,1],'--r')
self.ax3.plot([self.xmin,self.xmax],[0,0],'--r')
self.ax3.set_xlim(xmin,xmax)
#Update plotting window
self.TweakPlot.draw()
#Function for closing the current MPL event by it's ID, and stop the event loop
#It might seem redundant that I have both things, but I intend to have a continous
#editing method, which would need the looper.
def QuitEdit(self,cid):
#Close event ID
self.TweakPlot.mpl_disconnect(cid)
#Stop event loop
self.TweakPlot.stop_event_loop()
#Function when "Add Point" button is clicked.
def AddPoint(self):
#Show Tutorial message for what to do.
if usetutorial: tkMessageBox.showinfo("Help Message", "Click where to add point.")
#Start mouse click event, and run CT.ClickAdd
self.cidbut=self.TweakPlot.mpl_connect('button_press_event',self.ClickAdd)
self.TweakPlot.start_event_loop(0)
#If use continuous button is on, repeat adding points
while self.useContinuous.get():
if usetutorial: tkMessageBox.showinfo("Help Message", "Continuous point addition on. Keep adding points.")
try:
self.cidbut=self.TweakPlot.mpl_connect('button_press_event',self.ClickAdd)
self.TweakPlot.start_event_loop(0)
except: self.useContinuous.set(False)
#Given a mouse event for adding a point...
def ClickAdd(self,event):
#Grab the x/y coordiantes of the click, and add to spline
self.xspline.append(event.xdata)
self.yspline.append(event.ydata)
#Sort the spline data to be in order by wavelength
self.xspline,self.yspline=SortList(self.xspline,self.yspline)
#Refresh the plot with new data, but keep y-axis
self.Refresh(yrefresh=False)
#Close the MPL event stuff
self.QuitEdit(self.cidbut)
#Function ro remove a point when "Remove Point" button pressed
def RemovePoint(self):
#Show tutorial message on what to do
if usetutorial: tkMessageBox.showinfo("Help Message", "Click point to remove.")
#Start MPL event for picking an MPL artist, and start the loop. Run CT.ClickRemove
示例5: wishbone_gui
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_disconnect [as 别名]
#.........这里部分代码省略.........
self.geneSelectBox = tk.Listbox(self.geneSelection, selectmode=tk.EXTENDED)
self.geneSelectBox.grid(row=2, rowspan=10)
self.geneSelectBox.bind('<BackSpace>', self.DeleteSelected)
self.selectedGenes = []
tk.Button(self.geneSelection, text="Use selected genes", command=self.geneSelection.destroy).grid(row=12)
tk.Button(self.geneSelection, text="Cancel", command=self.cancelGeneSelection).grid(row=13)
self.wait_window(self.geneSelection)
def cancelGeneSelection(self):
self.selectedGenes = []
self.geneSelection.destroy()
def AddToSelected(self, event):
self.selectedGenes.append(self.geneInput.get())
self.geneSelectBox.insert(tk.END, self.selectedGenes[len(self.selectedGenes)-1])
def DeleteSelected(self, event):
selected = self.geneSelectBox.curselection()
pos = 0
for i in selected:
idx = int(i) - pos
self.geneSelectBox.delete( idx,idx )
self.selectedGenes = self.selectedGenes[:idx] + self.selectedGenes[idx+1:]
pos = pos + 1
def savePlot(self):
self.plotFileName = filedialog.asksaveasfilename(title='Save Plot', defaultextension='.png', initialfile=self.fileNameEntryVar.get()+"_"+self.currentPlot)
if self.plotFileName != None:
self.fig.savefig(self.plotFileName)
def setGate(self):
#pop up for gate name
self.gateOptions = tk.Toplevel()
self.gateOptions.title("Create gate for start cells")
tk.Label(self.gateOptions,text=u"Gate name:" ,fg="black",bg="white").grid(column=0, row=0)
self.gateName = tk.StringVar()
self.gateName.set('Gate ' + str(len(self.gates) + 1))
tk.Entry(self.gateOptions, textvariable=self.gateName).grid(column=1,row=0)
tk.Button(self.gateOptions, text="Select gate", command=self._setGate).grid(column=1, row=1)
tk.Button(self.gateOptions, text="Cancel", command=self.gateOptions.destroy).grid(column=0, row=1)
self.wait_window(self.gateOptions)
def _setGate(self):
self.gateOptions.destroy()
self.buttonPress = self.canvas.mpl_connect('button_press_event', self._startGate)
self.buttonRelease = self.canvas.mpl_connect('button_release_event', self._endGate)
self.canvas.get_tk_widget().config(cursor='plus')
def _startGate(self, event):
self.start_x = event.xdata
self.start_y = event.ydata
def _endGate(self, event):
#draw gate rectangle
start_x = self.start_x if self.start_x < event.xdata else event.xdata
start_y = self.start_y if self.start_y < event.ydata else event.ydata
width = np.absolute(event.xdata-self.start_x)
height = np.absolute(event.ydata-self.start_y)
rect = Rectangle((start_x, start_y), width, height,
fill=False, ec='black', alpha=1, lw=2)
self.ax.add_patch(rect)
self.canvas.draw()
#disable mouse events
self.canvas.mpl_disconnect(self.buttonPress)
self.canvas.mpl_disconnect(self.buttonRelease)
self.canvas.get_tk_widget().config(cursor='arrow')
#save cell gate
gate = Path([[start_x, start_y],
[start_x + width, start_y],
[start_x + width, start_y + height],
[start_x, start_y + height],
[start_x, start_y]])
gated_cells = self.scdata.tsne.index[gate.contains_points(self.scdata.tsne)]
self.gates[self.gateName.get()] = gated_cells
#replot tSNE w gate colored
self.fig.clf()
plt.scatter(self.scdata.tsne['x'], self.scdata.tsne['y'], s=10, edgecolors='none', color='lightgrey')
plt.scatter(self.scdata.tsne.ix[gated_cells, 'x'], self.scdata.tsne.ix[gated_cells, 'y'], s=10, edgecolors='none')
self.canvas.draw()
self.setGateButton.config(state='disabled')
self.visMenu.entryconfig(6, state='disabled')
def resetCanvas(self):
self.fig.clf()
if type(self.canvas) is FigureCanvasTkAgg:
for item in self.canvas.get_tk_widget().find_all():
self.canvas.get_tk_widget().delete(item)
else:
for item in self.canvas.find_all():
self.canvas.delete(item)
def quitWB(self):
self.quit()
self.destroy()
示例6: __init__
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_disconnect [as 别名]
#.........这里部分代码省略.........
self.ep_x_var[i].set('')
self.ep_y_var[i].set('')
self.sp_x[i].configure(text='')
self.sp_y[i].configure(text='')
self.ep_x[i].configure(text='')
self.ep_y[i].configure(text='')
self.clr.configure(state="disabled")
def canv_click_en(self,event):
try:
self.circ_e.remove()
except AttributeError:
pass
except ValueError:
pass
try:
txt="X "+str(rnd(event.xdata))+" Y "+str(rnd(event.ydata))
self.en_lab.configure(text=txt)
self.circ_e=patches.Circle((event.xdata,event.ydata),radius=5,color="red",fill=True)
self.sbplt.add_patch(self.circ_e)
self.canvas.draw()
self.en_x_var.set(str(rnd(event.xdata)))
self.en_y_var.set(str(rnd(event.ydata)))
except TypeError:
pass
self.canvas.mpl_disconnect(self.cid_en)
self.frame.configure(cursor="")
self.clr.configure(state="normal")
if self.st_x_var.get()!='' and self.st_y_var.get()!='' and self.en_x_var.get()!='' and self.en_y_var.get()!='':
self.ok.configure(state="normal")
def canv_click_st(self,event):
try:
self.circ_s.remove()
except AttributeError:
pass
except ValueError:
pass
try:
txt="X "+str(rnd(event.xdata))+" Y "+str(rnd(event.ydata))
self.st_lab.configure(text=txt)
self.circ_s=patches.Circle((event.xdata,event.ydata),radius=5,color="green",fill=True)
self.sbplt.add_patch(self.circ_s)
self.canvas.draw()
self.st_x_var.set(str(rnd(event.xdata)))
self.st_y_var.set(str(rnd(event.ydata)))
except TypeError:
pass
self.canvas.mpl_disconnect(self.cid_st)