本文整理汇总了Python中matplotlib.backends.backend_tkagg.FigureCanvasTkAgg.start_event_loop方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasTkAgg.start_event_loop方法的具体用法?Python FigureCanvasTkAgg.start_event_loop怎么用?Python FigureCanvasTkAgg.start_event_loop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_tkagg.FigureCanvasTkAgg
的用法示例。
在下文中一共展示了FigureCanvasTkAgg.start_event_loop方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import start_event_loop [as 别名]
#.........这里部分代码省略.........
def Pause(self):
self.stop = True
self.play_button['image'] = self.playfig
self.play_button['command'] = self.Play
def Forward(self):
self.stop = True
self.play_button['image'] = self.playfig
self.play_button['command'] = self.Play
self.jt += 1
self.jt = self.jt%self.nt
self.update_plot()
def Backward(self):
if not hasattr(self, 'jt'):
print('Run\n File-> Read and fit separatrix\nfirst')
return
self.stop = True
self.play_button['image'] = self.playfig
self.play_button['command'] = self.Play
self.jt -= 1
self.jt = self.jt%self.nt
self.update_plot()
def Play(self):
self.stop = False
self.play_button['image'] = self.pausefig
self.play_button['command'] = self.Pause
timeout = 1e-10
while (self.jt < self.nt-1) and (not self.stop):
self.jt += 1
self.update_plot()
self.pol_canvas.start_event_loop(timeout)
def updateTimeSlider(self, val=None):
if val == None:
progress = (self.fit.tarr[self.jt] - self.fit.tarr[0])/(self.fit.tarr[-1] - self.fit.tarr[0])
else:
progress = val
self.sl_time.val = progress
poly = self.sl_time.poly.get_xy()
poly[2:4, 0] = progress
self.sl_time.poly.set_xy(poly)
self.sl_time.valtext.set_text('%8.4f' %self.fit.tarr[self.jt])
def update_plot(self, val=None):
if val != None:
tloc = self.fit.tarr[0] + val*(self.fit.tarr[-1] - self.fit.tarr[0])
self.jt = np.argmin(np.abs(self.fit.tarr - tloc))
if not hasattr(self, 'fit'):
return
self.sepscat.set_data(self.fit.rscat[self.jt], self.fit.zscat[self.jt])
if self.fit.ind_ok[self.jt]:
self.sepfit.set_visible(True)
self.sepfit.set_data(self.fit.r_bnd[self.jt], self.fit.z_bnd[self.jt])
else:
self.sepfit.set_visible(False)
self.mag.set_data(self.fit.Rmag[self.jt], self.fit.Zmag[self.jt])
if hasattr(self.fit, 'Rzunt'):
self.u.set_data( self.fit.Rzunt[self.jt], self.fit.Zunt[self.jt])
self.o.set_data(self.fit.Rzoben[self.jt], self.fit.Zoben[self.jt])
示例2: __init__
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import start_event_loop [as 别名]
#.........这里部分代码省略.........
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
self.cidpick=self.TweakPlot.mpl_connect('pick_event',self.ClickRemove)
self.TweakPlot.start_event_loop(0)
#If Use continuous button is on, repeat removing points
while self.useContinuous.get():
if usetutorial: tkMessageBox.showinfo("Help Message", "Continuous point removal on. Keep removing points.")
try:
self.cidpick=self.TweakPlot.mpl_connect('pick_event',self.ClickRemove)
self.TweakPlot.start_event_loop(0)
except:
self.useContinuous.set(False)
#Given a picker event for removing a point...
def ClickRemove(self,event):
#Get the spline point that you picked, it's x and y coordinates
splinepoint = event.artist
xsplineval=splinepoint.get_xdata()
ysplineval=splinepoint.get_ydata()
#Index of the artist
ind = event.ind
#Make sure the point is in the spline point lists
if xsplineval[ind] in self.xspline:
if ysplineval[ind] in self.yspline:
#Remove that point from the spline, I think this is where sorting is important...
self.xspline.pop(ind)
self.yspline.pop(ind)
#Refresh the plot with new spline, but keep y-axis
self.Refresh(yrefresh=False)
#Close the event and stop the event loop
self.QuitEdit(self.cidpick)
#Function saves the spline using SaveSpline function
def Save(self):
print "Saving Spline"
SaveSpline(self.xspline,self.yspline,self.iwvlngth,self.outfile)
#Destroy CT.POPUP and CT.TFROOT (the masters for the CT buttons and plots) and leave CT.
def Exit(self):
self.popup.destroy()
self.TFroot.destroy()
return
示例3: __init__
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import start_event_loop [as 别名]
#.........这里部分代码省略.........
#------------
# Animation
#------------
def Pause(self):
self.stop = True
self.play_button['image'] = self.playfig
self.play_button['command'] = self.Play
def Forward(self):
self.stop = True
self.play_button['image'] = self.playfig
self.play_button['command'] = self.Play
self.jt += 1
self.jt = self.jt%self.nt
self.update_plot()
def Backward(self):
self.stop = True
self.play_button['image'] = self.playfig
self.play_button['command'] = self.Play
self.jt -= 1
self.jt = self.jt%self.nt
self.update_plot()
def Play(self):
self.stop = False
self.play_button['image'] = self.pausefig
self.play_button['command'] = self.Pause
while self.jt < self.nt-1 and not self.stop:
self.jt += 1
self.update_plot()
self.can_1d.start_event_loop(self.timeout)
def updateTimeSlider(self, val=None):
if val is None:
progress = (self.tgrid[self.jt] - self.tgrid[0])/(self.tgrid[-1] - self.tgrid[0])
else:
progress = val
self.sl_time.val = progress
poly = self.sl_time.poly.get_xy()
poly[2:4, 0] = progress
self.sl_time.poly.set_xy(poly)
self.sl_time.valtext.set_text('%8.4f' %self.tgrid[self.jt])
def update_plot(self, val=None):
self.update_plot1d(val=val)
if hasattr(self, 'y_fit'):
self.update_plot2d(val=val)
def update_plot1d(self, val=None):
if val is not None:
t_arr = self.tgrid[0] + val*(self.tgrid[-1] - self.tgrid[0])
self.jt = np.argmin(np.abs(self.tgrid - t_arr))
rho = self.xexp[self.jt]
dat = self.yexp[self.jt]
self.tlab = '#%d Time = %7.4f [s]' %(self.nshot, self.tgrid[self.jt])
self.ax1d.set_title(self.tlab, fontsize=fsize)
ymin = min(np.min(dat), 0)
if hasattr(self, 'y_fit'):
示例4: __init__
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import start_event_loop [as 别名]
#.........这里部分代码省略.........
self.stop = True
self.jtab = 0
self.jt = 0
self.set_plots()
def Pause(self):
self.stop = True
self.play_button['image'] = self.playfig
self.play_button['command'] = self.Play
def Forward(self):
self.stop = True
self.play_button['image'] = self.playfig
self.play_button['command'] = self.Play
self.jt += 1
self.jt = self.jt%self.nt
self.update_plot()
def Backward(self):
self.stop = True
self.play_button['image'] = self.playfig
self.play_button['command'] = self.Play
self.jt -= 1
self.jt = self.jt%self.nt
self.update_plot()
def Play(self):
self.stop = False
self.play_button['image'] = self.pausefig
self.play_button['command'] = self.Pause
while self.jt < self.nt-1 and not self.stop:
self.jt += 1
self.update_plot()
self.pol_canvas.start_event_loop(self.timeout)
def set_plots(self):
# Scale bar
self.crntsc = tk.Scale(self.toolframe, command=self.jump, \
orient=tk.HORIZONTAL, length=300)
self.crntsc.pack(side=tk.LEFT)
# Poloidal plot
self.tim0 = self.pol_fig.text(.5, .96, '', ha='center', va='top')
self.scat = self.pol_fig.add_subplot(111, aspect='equal')
self.scat.set_xlim((0.8, 3.0))
self.scat.set_ylim((-1.4, 1.4))
self.scat.set_xlabel('R [m]')
self.scat.set_ylabel('z [m]')
gc_r, gc_z = map_equ_20180130.get_gc()
for key in gc_r.keys():
self.scat.plot(gc_r[key], gc_z[key], 'b-')
self.rhoplot = {}
self.theplot = {}
self.theplot2 = {}
nt, n_rho_u, n_the_u = self.rsurf.shape
for jrho in range(n_rho_u):
self.theplot[jrho], = self.scat.plot([], [], 'g-')
self.theplot2[jrho], = self.scat.plot([], [], 'g-')
for jthe in range(n_the_u):
self.rhoplot[jthe], = self.scat.plot([], [], 'r-')
示例5: __init__
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import start_event_loop [as 别名]
#.........这里部分代码省略.........
self.mom_flag = False
self.set_sur()
self.jt = 0
self.update_plot()
def Pause(self):
self.stop = True
self.play_button['image'] = self.playfig
self.play_button['command'] = self.Play
def Forward(self):
self.stop = True
self.play_button['image'] = self.playfig
self.play_button['command'] = self.Play
self.jt += 1
self.jt = self.jt%self.nt
self.update_plot()
def Backward(self):
self.stop = True
self.play_button['image'] = self.playfig
self.play_button['command'] = self.Play
self.jt -= 1
self.jt = self.jt%self.nt
self.update_plot()
def Play(self):
self.stop = False
self.play_button['image'] = self.pausefig
self.play_button['command'] = self.Pause
while self.jt < self.nt-1 and not self.stop:
self.jt += 1
self.update_plot()
self.pol_canvas.start_event_loop(self.timeout)
def set_sur(self):
# Magnetic surfaces from NEMEC, interpolated on regular rho grid
self.pol_fig.clf()
self.pol_fig.text(.5, .95, r'NEMEC equilibrium, constant $\rho$ and constant $\theta$ contours', \
ha='center', va='top')
self.scat = self.pol_fig.add_subplot(111, aspect='equal')
self.scat.set_xlim((0.8, 3.0))
self.scat.set_ylim((-1.4, 1.4))
self.scat.set_xlabel('R [m]')
self.scat.set_ylabel('z [m]')
gc_r, gc_z = map_equ_20180130.get_gc()
for key in gc_r.iterjeys():
self.scat.plot(gc_r[key], gc_z[key], 'b-')
self.rhoplot = {}
self.theplot = {}
self.theplot2 = {}
nt, n_rho_u, n_the_u = self.rsurf.shape
for jrho in range(n_rho_u):
self.theplot[jrho], = self.scat.plot([], [], 'g-')
self.theplot2[jrho], = self.scat.plot([], [], 'g-')
for jthe in range(n_the_u):
self.rhoplot[jthe], = self.scat.plot([], [], 'r-')
sliderax = self.pol_fig.add_axes([0.1, 0.01, 0.6, 0.03], axisbg='yellow')
self.sl_time = Slider(sliderax,'Time:', 0., 1., valinit=0.)