Python Forum
How we can embed a metplotlib graph in tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How we can embed a metplotlib graph in tkinter
#1
Actually, i am pasting 2 code segments. The first code segment is generate the graph using matplotlib. while, second segment of code is for the usual tkinter window with tabs.

Now my question is that "How i can embed matplotlib plot of first segment of code into the tkinter window i.e. second segment of code?"

I am expecting same graph should be produced in tkinter window. I have gone through various tutorials available online and studied canvas method via figure but could not embed.

First Segment of Code:

import matplotlib.pyplot as plt
import pandas
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/pima-indians-diabetes/pima-indians-diabetes.data"
names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass', 'pedi', 'age', 'class']
data = pandas.read_csv(url, names=names)
data.hist()
plt.show()
Second Segment of Code:

import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.minsize(300, 300)
root.geometry("1000x700")
s = ttk.Style()
s.configure('TNotebook', tabposition='ne') #'ne' as in compass direction
box = ttk.Notebook(root, width=1000, height=650)
tab1 = tk.Frame(root)
tab2 = tk.Frame(root)
tab3 = tk.Frame(root)
box.add(tab1, text="tab1")
box.add(tab2, text="tab2")
box.add(tab3, text="tab3")
box.pack(side=tk.TOP)
root.mainloop()
Both codes are working fine separately, i tried lot but could not embed...plz check it out once. Thanks in Advance
Reply
#2
It is in matplotlib's documentation.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020