本文整理汇总了Python中matplotlib.backends.backend_tkagg.FigureCanvasTkAgg.mpl_connect方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasTkAgg.mpl_connect方法的具体用法?Python FigureCanvasTkAgg.mpl_connect怎么用?Python FigureCanvasTkAgg.mpl_connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.backends.backend_tkagg.FigureCanvasTkAgg
的用法示例。
在下文中一共展示了FigureCanvasTkAgg.mpl_connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MonitorWindow
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_connect [as 别名]
class MonitorWindow(PanedWindow):
def __init__(self, master, skeleton):
PanedWindow.__init__(self, master=master, height=400)
self.skeleton = skeleton
self.figure = Figure(figsize=(5,4), dpi=100)
self.subplots = {}
nrows = len(self.skeleton.units)
ncols = 3
plot_counter = 1
for u in self.skeleton.units.keys():
subplots = [None, None, None]
history = self.skeleton.units[u].history()
t = range(0, len(history[0]))
for a in range(0, 3):
subplot = self.figure.add_subplot(nrows, ncols, plot_counter, xlim=[0,200], ylim=[-90,90])
s = history[a]
subplot.plot(t,s)
plot_counter += 1
subplots[a] = subplot
self.subplots[u] = subplots
self.canvas = FigureCanvasTkAgg(self.figure, master=self)
self.canvas.show()
self.canvas.get_tk_widget().pack(side="top", fill="both", expand=1)
self.canvas.mpl_connect("key_press_event", self.pressed_key)
self.pack(fill="both", expand="yes")
def redraw_graph(self):
plot_counter = 1
for k, axes in self.subplots.iteritems():
history = self.skeleton.units[k].history()
t = range(0, len(history[0]))
for a, subplot in enumerate(axes):
s = history[a]
subplot.plot(t,s)
plot_counter += 1
subplot.clear()
subplot.plot(t,s)
subplot.set_xlim([0, 200])
subplot.set_ylim([-90, 90])
self.canvas.draw()
def pressed_key(self, event):
if event.key == "r":
self.redraw_graph()
else:
print("Key pressed: %s" % event.key)
示例2: LiveGraphTk
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_connect [as 别名]
class LiveGraphTk(Backend):
""" LiveGraph backend for Tkinter.
"""
def show(self, delay):
if self.master is None:
self.root = Tk.Toplevel()
self.master = self.root
else:
self.root = Tk.Toplevel(self.master)
self.canvas = FigureCanvasTkAgg(self.figure, master=self.root)
#self.canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
self.toolbar = NavigationToolbar2TkAgg(self.canvas, self.root)
self.toolbar.update()
self.canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=True)
self.canvas.mpl_connect('key_press_event', self.on_key_event)
self.root.protocol("WM_DELETE_WINDOW", self.close)
super().show(delay)
def run(self, delay):
"""Calls the update method periodically with the delay in milliseconds.
Decrease the delay to make the plotting smoother and increase it to
reduce the preformance. For live plotting the delay must fit the rate
of the incoming data.
Keyword arguments:
delay -- the delay in millisconds after each call (default 50)
"""
super().run()
self.root.after(delay, self.run, delay)
@property
def visible(self):
if self.root.state() in ['normal', 'zoomed']:
return True
else:
return False
@visible.setter
def visible(self, boolean):
if boolean:
self.root.deiconify()
else:
self.root.withdraw()
self.visible = False
def close(self):
super().close()
self.master.destroy()
示例3: Graph
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_connect [as 别名]
class Graph(tk.Frame,object):
def __init__(self,master=None,onClick=None,xSize=40,ySize=30):
self.onClick=(lambda x,y,z:None) if onClick is None else onClick
tk.Frame.__init__(self,master)
self.f = Figure(figsize=(4,4), dpi=100) # return a matplotlib.figure.Figure instance, Höhe und Breite in Inches
self.a = self.f.add_subplot(111) # Add a subplot with static key "111" and return instance to it
self.a.grid(True) # Set the axes grids on
self.a.set_xlim((0,ySize))
self.a.set_ylim((0,xSize))
self.canvas = FigureCanvasTkAgg(self.f, master=self) # The Canvas widget provides structured graphics facilities for Tkinter.
self.canvas.mpl_connect('button_press_event', self.rawOnClick)
self.canvas.show() # Aus matplotlib: display all figures and block until the figures have been closed
self.canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
def addline(self,x,y):
self.curline=matplotlib.lines.Line2D([y],[x])
self.a.add_line(self.curline)
def append(self,x,y):
y0,x0=self.curline.get_data()
x0.append(x)
y0.append(y)
self.curline.set_data(y0,x0)
self.canvas.draw()
def rawOnClick(self,evt):
print evt.key
both=True if evt.key=='shift' else False
self.onClick(evt.ydata, evt.xdata, both)
示例4: __init__
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_connect [as 别名]
def __init__(self, root, controller):
f = Figure()
ax = f.add_subplot(111)
ax.set_xticks([])
ax.set_yticks([])
ax.set_xlim((x_min, x_max))
ax.set_ylim((y_min, y_max))
canvas = FigureCanvasTkAgg(f, master=root)
canvas.show()
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
canvas.mpl_connect('button_press_event', self.onclick)
toolbar = NavigationToolbar2TkAgg(canvas, root)
toolbar.update()
self.controllbar = ControllBar(root, controller)
self.menubar = MenuBar(root, controller)
self.f = f
self.ax = ax
self.canvas = canvas
self.controller = controller
self.contours = []
self.tube = []
self.c_labels = None
self.plot_kernels()
self.class_colors = ('b', 'r', 'g', 'y')
示例5: PlotWindow
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_connect [as 别名]
class PlotWindow(Frame):
"""
"""
def __init__(self, parent, figure, plotType=None):
"""
Constructor
@param parent:
@param figure:
@param plotType:
@return
"""
Frame.__init__(self, parent)
# a tk.DrawingAre
self.plotType = plotType
self.canvas = FigureCanvasTkAgg(figure, master=self)
self.canvas.show()
self.canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
self.toolbar = NavigationToolbar2TkAgg(self.canvas, self)
self.toolbar.update()
self.canvas._tkcanvas.pack(side=TOP, fill=BOTH, expand=1)
self.canvas.mpl_connect('key_press_event', self.on_key_event)
def getPlotType(self):
"""
@return
"""
return self.plotType
def updateFigure(self, figure):
"""
@param figure:
@return
"""
self.canvas._tkcanvas.pack_forget()
self.canvas = FigureCanvasTkAgg(figure, master=self)
self.canvas.show()
self.canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
self.toolbar = NavigationToolbar2TkAgg(self.canvas, self)
self.toolbar.update()
self.canvas._tkcanvas.pack(side=TOP, fill=BOTH, expand=1)
self.canvas.mpl_connect('key_press_event', self.on_key_event)
def on_key_event(self, event):
"""
@param event:
@return
"""
print('you pressed %s' % event.key)
key_press_handler(event, self.canvas, self.toolbar)
示例6: __init__
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_connect [as 别名]
def __init__(self, root, f):
Tk.Frame.__init__(self, root)
# a tk.DrawingArea
canvas = FigureCanvasTkAgg(f, root)
canvas.show()
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
toolbar = NavigationToolbar2TkAgg(canvas, root)
toolbar.update()
canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
def on_key_event(event):
print('you pressed %s' % event.key)
key_press_handler(event, canvas, toolbar)
canvas.mpl_connect('key_press_event', on_key_event)
def _quit():
root.quit() # stops mainloop
root.destroy() # this is necessary on Windows to prevent
# Fatal Python Error: PyEval_RestoreThread: NULL tstate
button = Tk.Button(root, text='Quit', command=_quit)
button.pack(side=Tk.BOTTOM)
示例7: __init__
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_connect [as 别名]
def __init__(self, master, controller):
def onClick(event):
global pause
pause ^= True
global ser, instrument
Frame.__init__(self, master)
self.graphframe = Frame(self)
self.graphframe.pack(side = TOP, fill=BOTH, expand=True)
self.filenameframe = Frame(self)
self.filenameframe.pack(side = BOTTOM, fill=BOTH, pady = 10)
self.browseframe = Frame(self)
self.browseframe.pack(side = BOTTOM, fill=BOTH, pady = 10)
self.title = ttk.Label(self.graphframe, text = "Pressure Reading from Pads", font = ("", "14", "bold"))
self.title.pack(pady = 10, padx = 10)
# figure window
canvas = FigureCanvasTkAgg(f, self.graphframe)
canvas.show()
canvas.get_tk_widget().pack(side=BOTTOM, fill=BOTH, expand=True)
canvas.mpl_connect('button_press_event', onClick)
toolbar = NavigationToolbar2TkAgg(canvas, self.graphframe)
toolbar.update()
canvas._tkcanvas.pack(side=TOP, fill=BOTH, expand=True)
self.filepath = StringVar()
self.filename = StringVar()
self.filename.set(str(strftime("%d-%m-%Y_%H%M", gmtime())) + '.mid')
browse_label = ttk.Label(self.browseframe, text = "Save MIDI file in:")
browse_label.pack(side = LEFT, fill=Y, padx = 5)
self.browse_filepath = ttk.Entry(self.browseframe, textvariable = self.filepath)
self.browse_filepath.pack(side = LEFT, fill=X, expand=True, padx = 5)
browse_button = ttk.Button(self.browseframe, text = "Browse", command = self.askopenfile)
browse_button.pack(side = LEFT, fill=BOTH, padx = 5)
filename_label = ttk.Label(self.filenameframe, text = "MIDI filename:")
filename_label.pack(side = LEFT, fill=Y, padx = 5)
self.saveFileName = ttk.Entry(self.filenameframe, textvariable = self.filename)
self.saveFileName.pack(side = LEFT, fill=X, expand=True, padx = 5)
browse_button = ttk.Button(self.filenameframe, text = "Save", command = self.savefile)
browse_button.pack(side = LEFT, fill=BOTH, padx = 5)
示例8: __init__
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_connect [as 别名]
def __init__(self, master):
super(ImageFrame, self).__init__(master)
figure = Figure((5,4), dpi=100)
self.figure = figure
canvas = FigureCanvasTkAgg(figure, master=master)
canvas.mpl_connect('button_press_event', self._on_click)
canvas.mpl_connect('key_press_event',self._on_keypress)
canvas.show()
self.__canvas = canvas
toolbar = NavigationToolbar2TkAgg(canvas, master)
toolbar.update()
canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=YES)
toolbar.pack()
self.axes = figure.add_subplot(111)
self.peakFinder = PeakFinder(self.axes, canvas)
示例9: __init__
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_connect [as 别名]
def __init__(self, master):
super().__init__(master)
figure = Figure((5,4), dpi=100)
self.figure = figure
canvas = FigureCanvasTkAgg(figure, master=master)
canvas.mpl_connect('button_press_event', self._on_click)
canvas.mpl_connect('key_press_event',self._on_keypress)
canvas.draw()
self.__canvas = canvas
toolbar = NavigationToolbar2TkAgg(canvas, master)
toolbar.update()
canvas.get_tk_widget().pack(side='top', fill='both', expand='yes')
toolbar.pack()
self.axes = figure.add_subplot(111)
self.__rectselector = RectSelector(self.axes, canvas)
示例10: draw
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_connect [as 别名]
def draw():
def on_key_event(event):
print('you pressed %s' % event.key)
key_press_handler(event, canvas, toolbar)
fig = Figure(figsize=(5, 4), dpi=100)
ax = fig.add_subplot(111)
x = arange(0.0, 3.0, 0.01)
y=eval(entry.get()+"(x)")
ax.set_title(entry.get())
ax.plot(x, y)
ax.set_xlabel('x')
ax.set_ylabel('y')
canvas = FigureCanvasTkAgg(fig, master=root)
canvas.show()
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
toolbar = NavigationToolbar2TkAgg(canvas, root)
toolbar.update()
canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
canvas.mpl_connect('key_press_event', on_key_event)
示例11: __init__
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_connect [as 别名]
def __init__(self):
self.root = tk.Tk()
self.root.wm_title("AEViewer")
self.make_menu()
frame = tk.Frame(self.root)
frame.pack(side=tk.TOP, fill=tk.BOTH, expand=1)
self.fig = Figure(figsize=(8,6), dpi=100)
canvas = FigureCanvasTkAgg(self.fig, frame)
canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
self.toolbar = NavigationToolbar2TkAgg(canvas, frame)
canvas.mpl_connect('key_press_event', self.on_key_press)
canvas.mpl_connect('scroll_event', self.on_scroll)
self.progressbar = ttk.Progressbar(self.root, orient='horizontal', mode='determinate', )
self.progressbar.pack(side=tk.BOTTOM, fill=tk.X)
self.data = None
self.root.update() # needed on windows for events to work
示例12: __init__
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_connect [as 别名]
def __init__(self, abs_path_to_csv, var_names):
self.check_vars(var_names)
self._root = Tk.Tk()
self._root.wm_title("pyDataGate")
self._figure = Figure(figsize=(5,4), dpi=100)
self._dataset = DataSet(abs_path)
root = self._root
f = self._figure
canvas = FigureCanvasTkAgg(f, master=root)
canvas.show()
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
canvas.mpl_connect('button_press_event', self.on_click_event)
arrays = []
for a_var in var_names:
arrays.append(self._dataset.get_array_from_dicts(a_var))
if len(var_names) == 2:
ax = f.add_subplot(111)
ax.scatter(arrays[0], arrays[1])
if len(var_names) == 3:
ax = f.add_subplot(111)
ax.scatter(arrays[0], arrays[1], c=arrays[2])
button = Tk.Button(master=root, text='Quit', command=self.quit)
button.pack(side=Tk.BOTTOM)
示例13: __init__
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_connect [as 别名]
def __init__(self, root, controller):
f = Figure()
nticks = 10
ax = f.add_subplot(111, aspect='1')
ax.set_xticks([x*(x_max-x_min)/nticks+x_min for x in range(nticks+1)])
ax.set_yticks([y*(y_max-y_min)/nticks+y_min for y in range(1,nticks+1)])
ax.set_xlim((x_min, x_max))
ax.set_ylim((y_min, y_max))
canvas = FigureCanvasTkAgg(f, master=root)
canvas.show()
canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
canvas.mpl_connect('button_press_event', self.onclick)
toolbar = NavigationToolbar2TkAgg(canvas, root)
toolbar.update()
self.controllbar = ControllBar(root, controller)
self.f = f
self.ax = ax
self.canvas = canvas
self.controller = controller
self.contours = []
self.c_labels = None
self.plot_kernels()
示例14: fig_plot
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_connect [as 别名]
def fig_plot(frame, tarr, parr, nshot, y_ticks=[], col='#c00000', ylbl=''):
fig = Figure(figsize=(8.2, 8.2), dpi=100)
can = FigureCanvasTkAgg(fig, master=frame)
can._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=1)
fig.subplots_adjust(left=0.1, bottom=0.1, right=0.95, top=0.92, hspace=0)
fig.text(.5, .95, '#%d' %nshot, ha='center')
nsrc = parr.shape[1]
for jx in range(nsrc):
ax = fig.add_subplot(8, 1, jx+1)
ax.plot(tarr, parr[:, jx], color=col)
ax.set_ylabel('%s%d' %(ylbl, jx+1), fontsize=fsize)
ax.set_yticks(y_ticks)
ax.ticklabel_format(axis='y', style='sci', scilimits=(-4,-4))
ax.yaxis.major.formatter._useMathText = True
if jx < nsrc-1:
ax.tick_params(axis='x', which='both', bottom='on', top='on', labelbottom='off')
ax.set_xlabel('Time [s]', fontsize=fsize)
can.mpl_connect('button_press_event', fconf.on_click)
toolbar = NavigationToolbar2TkAgg(can, frame)
toolbar.update()
示例15: __init__
# 需要导入模块: from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg [as 别名]
# 或者: from matplotlib.backends.backend_tkagg.FigureCanvasTkAgg import mpl_connect [as 别名]
def __init__(self,root,listener=None):
self.root=root
fig,ax=plt.subplots(figsize=(6,6))
self.ax=ax
self.ax.set_xlim([0,255])
self.ax.set_ylim([0,255])
browser=ToneCurve(fig,self.ax,listener)
plot_frame=Frame(self.root)
self.root.add(plot_frame)
canvas=FigureCanvasTkAgg(fig,master=plot_frame)
canvas.mpl_connect('pick_event',browser.onpick)
canvas.mpl_connect('motion_notify_event',browser.on_motion)
#both bind is very important for release event but I do not know why
canvas._tkcanvas.bind('button_release_event',browser.on_release)
canvas.mpl_connect('button_release_event', browser.on_release)
toolbar = NavigationToolbar2TkAgg(canvas, plot_frame)
toolbar.update()
self.canvas=canvas
self.canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=1)