我们从Python开源项目中,提取了以下19个代码示例,用于说明如何使用matplotlib.backends.backend_tkagg.NavigationToolbar2TkAgg()。
def __init__(self, parent, controller): tk.Frame.__init__(self, parent) self.configure(bg=BG_COLOR) self.trends = Figure(figsize=(5, 5), dpi=100) self.a = self.trends.add_subplot(111) canvas = FigureCanvasTkAgg(self.trends, self) canvas.show() canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1) toolbar = NavigationToolbar2TkAgg(canvas, self) toolbar.update() canvas._tkcanvas.pack(side=tk.BOTTOM, fill=tk.BOTH, expand=1) self.animation = FuncAnimation(self.trends, self.animate, 5000)
def __init__(self, parent, controller): tk.Frame.__init__(self, parent) label = tk.Label(self, text="Graph Page!", font=LARGE_FONT) label.pack(pady=10,padx=10) button1 = ttk.Button(self, text="Back to Home", command=lambda: controller.show_frame(StartPage)) button1.pack() canvas = FigureCanvasTkAgg(f, self) canvas.show() canvas.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True) toolbar = NavigationToolbar2TkAgg(canvas, self) toolbar.update() canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)
def __init__(self, master = []): self.master = master # Erstellen des Fensters mit Rahmen und Canvas self.figure = Figure(figsize = (7, 7), dpi = 100) self.frame_c = Frame(relief = GROOVE, bd = 2) self.frame_c.pack(fill = BOTH, expand = 1,) self.canvas = FigureCanvasTkAgg(self.figure, master = self.frame_c) self.canvas.show() self.canvas.get_tk_widget().pack(fill = BOTH, expand = 1) # Erstellen der Toolbar unten self.toolbar = NavigationToolbar2TkAgg(self.canvas, self.frame_c) self.toolbar.update() self.canvas._tkcanvas.pack(fill = BOTH, expand = 1)
def __init__(self,master=[]): self.master=master #Erstellen des Fensters mit Rahmen und Canvas self.figure = Figure(figsize=(7,7), dpi=100) self.frame_c=Frame(relief = GROOVE,bd = 2) self.frame_c.pack(fill=BOTH, expand=1,) self.canvas = FigureCanvasTkAgg(self.figure, master=self.frame_c) self.canvas.show() self.canvas.get_tk_widget().pack(fill=BOTH, expand=1) #Erstellen der Toolbar unten self.toolbar = NavigationToolbar2TkAgg(self.canvas, self.frame_c) self.toolbar.update() self.canvas._tkcanvas.pack( fill=BOTH, expand=1)
def initialize_display(self): self.openButton = tk.Button(self, text = "Open File", command = self.get_filepath) self.openButton.grid(row = 0, column = 0) # This is just here to easily close the app during testing self.quitButton = tk.Button(self, text = "Quit", command = self.quit) self.quitButton.grid(row = 1, column = 0) # testing alternative plotting solution f = Figure(figsize=(5, 4), dpi=100) a = f.add_subplot(111) t = arange(0.0, 3.0, 0.01) s = sin(2*pi*t) a.plot(t, s) canvas = FigureCanvasTkAgg(f, master=drawing_panel) canvas.show() # canvas.get_tk_widget().grid(row = 10, column = 10) # canvas._tkcanvas.grid(row = 10, column = 10) 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 __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()
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.f = f self.ax = ax self.canvas = canvas self.controller = controller self.contours = [] self.c_labels = None self.plot_kernels()
def init_ui(self, root): self.figure = Figure(figsize=(5,5), dpi=100) self.subplot = self.figure.add_subplot(111) self.canvas = FigureCanvasTkAgg(self.figure, root) self.canvas.show() self.canvas.get_tk_widget().pack(fill=tk.BOTH, expand=1) toolbar = NavigationToolbar2TkAgg(self.canvas, root) toolbar.update()
def __init__(self, parent, plotdata, plotdata_files): self.parent = parent self.plots = plotdata # example: { "dgde" : { 0 : QPlotData_instance (from file 1), 1 : QPlotData_instance (from file 2) }, ... }, where 0,1,... are indices of the filenames in plotdata_files self.plotdata_files = plotdata_files # [ "/home/.../pro/qa.PlotData.pickle", "/home/.../wat/qa.PlotData.pickle" ] self.nrows = 1 self.ncols = 1 self.blocked_draw = False self.subplot_lines = {} self.COLORS_ACTIVE = ("#555555","#F75D59","#1589FF", "black", "red", "blue") self.COLORS_INACTIVE = ("#aaaaaa","#F7bDb9","#a5a9FF", "#999999", "#FFaaaa", "#aaaaFF") self.lb1_entries = ODict() for plot_key, plot in self.plots.iteritems(): self.lb1_entries[ plot.values()[0].title ] = plot_key self.lb1 = Tk.Listbox(self.parent, selectmode=Tk.EXTENDED, exportselection=0) for plot_title in self.lb1_entries.keys(): self.lb1.insert(Tk.END, plot_title) self.lb1.pack(fill=Tk.Y, side=Tk.LEFT) self.lb2 = Tk.Listbox(self.parent, selectmode=Tk.EXTENDED, exportselection=0) self.lb2.pack(fill=Tk.Y, side=Tk.LEFT) self.figure = Figure(figsize=(5,4), dpi=100) self.canvas = FigureCanvasTkAgg(self.figure, master=self.parent) self.canvas.get_tk_widget().pack() self.canvas._tkcanvas.pack(fill=Tk.BOTH, expand=1) self.toolbar = NavigationToolbar2TkAgg( self.canvas, self.parent ) self.toolbar.update() self.canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1) self.lb1.bind("<<ListboxSelect>>", self.on_select_lb1) self.lb2.bind("<<ListboxSelect>>", self.on_select_lb2) self.parent.bind("<Configure>", self.on_resize)
def __init__(self, master=[]): self.master = master #Erstellen des Fensters mit Rahmen und Canvas self.figure = Figure(figsize=(7, 7), dpi=100) self.frame_c = Frame(relief = GROOVE, bd = 2) self.frame_c.pack(fill=BOTH, expand=1,) self.canvas = FigureCanvasTkAgg(self.figure, master=self.frame_c) self.canvas.show() self.canvas.get_tk_widget().pack(fill=BOTH, expand=1) #Erstellen der Toolbar unten self.toolbar = NavigationToolbar2TkAgg(self.canvas, self.frame_c) self.toolbar.update() self.canvas._tkcanvas.pack(fill=BOTH, expand=1)
def __init__(self, master=None, iter=None): self.master = master self.iter = iter self.frame_o = Frame(height=50, relief=GROOVE, bd=2) self.frame_o.pack(fill=BOTH, expand=1) self.but_update_plot = Button(master=self.frame_o, text='Start Animation', command=self.iter.start_animation) self.but_update_plot.pack(fill=BOTH, expand=1) self.figure = Figure(figsize=(6, 7), dpi=100) # a tk.DrawingArea self.frame_c = Frame(relief = GROOVE, bd = 2) self.frame_c.pack(fill=BOTH, expand=1,) self.canvas = FigureCanvasTkAgg(self.figure, master=self.frame_c) self.canvas.show() self.canvas.get_tk_widget().pack(fill=BOTH, expand=1) self.toolbar = NavigationToolbar2TkAgg(self.canvas, self.frame_c) self.toolbar.update() self.canvas._tkcanvas.pack( fill=BOTH, expand=1) self.ini_plot()
def create_canvas(self): """Creates a canvas object to draw matplotlib visualizations on self.f - Figure - contains the figure object for all of the subplots self.a - Plot - the plot in question. self.canvas - FigureCanvasTkAgg - tkinter widget that holds figure""" self.f = Figure(figsize = (6,4), dpi = 100) self.a = self.f.add_subplot(111) self.canvas = FigureCanvasTkAgg(self.f, master=self) self.canvas.get_tk_widget().grid(column=3, row=1, rowspan=5, columnspan = 6, sticky="nesw") self.toolbar = NavigationToolbar2TkAgg(self.canvas, self.master) #do we want to keep this? it allows the user to save the plot so probs useful
def create_app_graph(self): """ Create app graph """ self.graph_figure = Figure(figsize=(4.4, 2.8), dpi=100) self.graph = FigureCanvasTkAgg(self.graph_figure, master=self.frame_top) self.graph.get_tk_widget().pack(side=LEFT, expand=NO, anchor=NW) # EMBED GRAPH TOOLBAR self.graph_toolbar = NavigationToolbar2TkAgg(self.graph, self.frame_bottom).pack(side=LEFT) # PLOT STARTING PLOT self.subplot = self.graph_figure.add_subplot(111) self.lines = self.subplot.plot([1, 2, 3], [1, 2, 3]) self.change_xy_label('t(s)', 'magnitude')
def __init__(self, parent): self.parent = parent tk.Frame.__init__(self, self.parent) self.updateplot(None) self.canvas.get_tk_widget().pack(side='top', fill='both', expand=1) self.toolbar = NavigationToolbar2TkAgg(self.canvas, self.parent) self.toolbar.update() self.canvas._tkcanvas.pack(fill='both', expand=1)
def __init__(self, master, figsize=(9, 6)): tk.Frame.__init__(self, master) self.figure = Figure(figsize=figsize) self.canvas = FigureCanvasTkAgg(self.figure, master=self) self.canvas.show() self.canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1) self.toolbar = NavigationToolbar2TkAgg(self.canvas, self) self.toolbar.update()
def __init__(self, parent, controller, number_of_months, balances, interests, principals): tk.Frame.__init__(self, parent) self.controller = controller label = tk.Label(self, text="Mortgage Visualization", font=LARGE_FONT) label.pack(pady=10,padx=10) Button(self, text="Back", command=lambda: controller.show_frame(InputPage)).pack() months = list() i = 1 while i <= number_of_months: months.append(i) i = i + 1 f = Figure() f.subplots_adjust(left=0.15, right=0.95, wspace=0.25, hspace=0.75) a = f.add_subplot(211) plot1, = a.plot(months, interests,'r') plot2, = a.plot(months, principals,'g') b = f.add_subplot(212) plot3 = b.plot(months, balances, 'b') canvas = FigureCanvasTkAgg(f, self) canvas.show() canvas.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True) toolbar = NavigationToolbar2TkAgg(canvas, self) toolbar.update() canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=True)