How to add a Matplotlib chart on Tkinter

Asked

Viewed 432 times

1

I have a graphic of matplotlib put in format (pizza) and I wanted to take the picture and add it to Tkinter matplotlib.use("Tkagg")

DataBaser.cursor.execute("""
SELECT RendaMensal FROM Registro
Where Status = 'On'
""")

RendaGet = DataBaser.cursor.fetchone()

Renda = RendaGet[0]

print(Renda)

DataBaser.cursor.execute("""
SELECT TotalDebt FROM Registro
Where Status = 'On'
""")

TotalDebt = DataBaser.cursor.fetchone()

Debt = TotalDebt[0]

print(Debt)

sizes = [Debt, Renda]

labels = 'Gastos', 'Renda'

fig1, axl = plt.subplots()

colors = ['red', 'green']

c2 = axl.pie(sizes, labels=labels, autopct='%0.0f%%', shadow=False, startangle=90, colors=colors)

axl.axis('equal')

circle = axl.axis('equal')

#plt.xticks(Renda)


plt.title("Controle do Limite")
plt.show()
canvas = FigureCanvasTkAgg(c2, DataFrame)
canvas.draw()
canvas.get_tk_widget().pack(side=LEFT, fill=BOTH, expand=True)
#canvas._tkcanvas.pack(side=tk.BOTTOM, fill=tk.BOTH, expand = True)

1 answer

1


I am creating 2 figures, fig1, in which Voce uses to plot the pie style pizza (pie Chart) and f in which Voce uses to work the Figurecanvastkagg. Removing f and using fig1 in Figurecanvastkagg

Something like:

fig1, axl = plt.subplots()
c2 = axl.pie(sizes, labels=labels, autopct='%0.0f%%', shadow=False, startangle=90,  colors=colors)
canvas = FigureCanvasTkAgg(fig1, master=DataFrame)
canvas.draw()
canvas.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH, expand = True)
Respondido no StackOverflow(USA) por: **Diziet Asahi**

Browser other questions tagged

You are not signed in. Login or sign up in order to post.