I am creating a program that incorportes matplotlib into tkinter. The majority of the program works including displaying the canvas of the graph, however, the graph title,navigation toolbar and the xy legends do not show. The part of the code I am wondering about is right at the bottom of the script:
toolbar = NavigationToolbar2TkAgg( canvas, root )
toolbar.update()
canvas._tkcanvas.grid(row=9,column=0)
plt.xlabel('x label')
plt.ylabel('y label')
plt.title('Graph')
plt.show()
Does anyone have any suggestions? Any help would be extremely appreciated!
from matplotlib import pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
from tkinter import *
import tkinter as Tk
import numpy as np
import math
import matplotlib
matplotlib.use('TkAgg')
from matplotlib.backend_bases import key_press_handler
import sys
root = Tk.Tk()
#Interface-----------------------------------------------------------
title_label = Button(root,text = "Add graph title", padx=2,pady=2)
xlabel = Button(root,text = "Add X values ", padx=2,pady=2)
ylabel = Button(root,text = "Add Y values ", padx=2,pady=2)
nameXaxis = Button(root,text = "Name X axis ", padx=2,pady=2)
nameYaxis = Button(root,text = "Name Y axis ", padx=2,pady=2)
meanLabel = Button(root,text = "Mean ")
stderrorLabel = Button(root,text = "StdError: ")
barGraph = Button(root,text = "Bar Graph ",fg = "red", padx=2,pady=2)
lineGraph = Button(root,text = "Line Graph", fg = "red",padx=2,pady=2)
pieGraph = Button(root,text = "Pie Graph ",fg = "red",padx=2,pady=2)
titleEntry = Entry(root)
xentry = Entry(root)
yentry = Entry(root)
nameXaxisEntry = Entry(root)
nameYaxisEntry = Entry(root)
meanText = Text(root,height=1,width=4)
stderrText = Text(root,height=1,width=4)
title_label.grid(row = 0, column = 0,sticky = E)
xlabel.grid(row = 1, column = 0, sticky = E)
ylabel.grid(row = 2, column = 0, sticky = E)
nameXaxis.grid(row = 3, column = 0, sticky = E)
nameYaxis.grid(row = 4, column = 0, sticky = E)
barGraph.grid(row = 0,column = 1,ipadx=10,sticky=W)
lineGraph.grid(row = 1,column = 1,ipadx=10,sticky=W)
pieGraph.grid(row = 2,column = 1,ipadx=10,sticky=W)
meanLabel.grid(row = 3,column = 1,ipadx=10,sticky=W)
stderrorLabel.grid(row = 4,column = 1,ipadx=10,sticky=W)
titleEntry.grid(row = 0, column = 0,ipadx=100,sticky=W)
xentry.grid(row = 1, column = 0,ipadx=100,sticky=W)
yentry.grid(row = 2, column = 0,ipadx=100,sticky=W)
nameXaxisEntry.grid(row = 3, column = 0,ipadx=100,sticky=W)
nameYaxisEntry.grid(row = 4, column = 0,ipadx=100,sticky=W)
meanText.grid(row=3,column=3,sticky=W)
stderrText.grid(row=4,column=3,sticky=W)
# Adding line graph to Canvas--------------------------------------------
root.title("Naynts Graphs")
fig = Figure(figsize=(5,4), dpi=100)
ax = fig.add_subplot(111)
canvas = FigureCanvasTkAgg(fig,root)
canvas.show()
canvas.get_tk_widget().grid(row=7,column=0)
toolbar = NavigationToolbar2TkAgg( canvas, root )
toolbar.update()
canvas._tkcanvas.grid(row=9,column=0)
# Adding features to graph
plt.xlabel('x label')
plt.ylabel('y label')
plt.title('Graph')
plt.show()
root.mainloop()