how to place a plot in a tkinter frame

Solutions on MaxInterview for how to place a plot in a tkinter frame by the best coders in the world

showing results for - "how to place a plot in a tkinter frame"
Marta
28 Feb 2016
1from tkinter import *
2from pandas import *
3from math import sin
4import matplotlib.pyplot as plt
5from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
6
7# Data for plot
8df = DataFrame({'A': range(20),
9                'B': [sin(i) for i in range(20)]
10                }, index=range(20))  
11
12app = Tk()
13app.config(bg='lightgray')
14app.title("The title of the project")
15app.geometry("800x600")
16app.minsize(1000, 700)
17app.rowconfigure(0, weight=1)
18app.columnconfigure(3, weight=1)
19
20fr_plot = Frame(app)
21fr_plot.grid(row=0, column=1, sticky=N+S) 
22
23figure1 = plt.Figure(figsize=(5,4), dpi=80)
24ax1 = figure1.add_subplot()
25line1 = FigureCanvasTkAgg(figure1, fr_plot)
26line1.get_tk_widget().pack(side=TOP, fill=BOTH)
27df = df.iloc[:,1]
28df.plot(kind='line', legend=True, ax=ax1, color='r', marker='o', fontsize=10)
29ax1.set_title('Initial data')
30
31app.mainloop()