User interface 将Matplotlib子批次插入Tkinter GUI窗口

User interface 将Matplotlib子批次插入Tkinter GUI窗口,user-interface,matplotlib,tkinter,python-3.4,User Interface,Matplotlib,Tkinter,Python 3.4,我正在开发一个Tkinter GUI,我想知道是否有可能在Tkinter GUI中添加一个子窗口。任何帮助都将不胜感激,因为我目前不知道 import pandas.io.data as web import matplotlib.pyplot as plt import datetime start = datetime.datetime(2010, 1, 1) end = datetime.datetime(2014, 8, 3) google = web.DataReader("GOO

我正在开发一个Tkinter GUI,我想知道是否有可能在Tkinter GUI中添加一个子窗口。任何帮助都将不胜感激,因为我目前不知道

import pandas.io.data as web
import matplotlib.pyplot as plt
import datetime

start = datetime.datetime(2010, 1, 1)
end = datetime.datetime(2014, 8, 3)

google = web.DataReader("GOOG", 'yahoo', start, end )

ax1 = plt.subplot2grid((4,4), (0,0), colspan=4)
ax2 = plt.subplot2grid((4,4), (1,0), colspan=2)

top = plt.subplot2grid((4,4), (0, 0), rowspan=3, colspan=4)
top.plot(google.index, google["Close"])
plt.title('Google Stock Price from 2007 - 2012')

bottom = plt.subplot2grid((4,4), (3,0), rowspan=1, colspan=4)
bottom.bar(google.index, google['Volume'])
plt.title('Google Trading Volume in Millions')

plt.gcf().set_size_inches(15,8)
plt.show()
我正在做一些相关的工作,但是如果没有一个完全独立的窗口,我无法将它放入GUI中

self.root2= Tk()
self.root2.geometry("600x400")
self.root2.title("Stock Visualization")
frame = Frame(self.root2)
frame.grid(row=2,column=0, sticky="s")
frame2 = Frame(self.root2)
frame2.grid(row=0,column=0, sticky = "n")
##        self.canvas=Canvas(self.root2, width=300, height=300, background='white')
##        self.canvas.grid(row=1,column=0, columnspan = 4)

这是框架的一部分,周围没有所有标签等。我已经在画布上注释了我希望子地块的位置。

这可能有点晚了,但您应该尝试类似的方法

     fig = Figure(figsize=(5,4), dpi = 100)
     ax = fig.add_subplot(111)
     figcanvas = FigureCanvasTkAgg(fig, master = root)
     plotthis(figcanvas, ax)#in this example plotthis is a function that plots the figure, ax being a graph, and figcanvas being the canvas of which the graph is being plotted to.
     figcanvas.get_tk_widget().grid()

稍微提醒一下,我认为这种方法在3中还不起作用,所以到目前为止,如果可能的话,我会在2中完成。不知道为什么它在3中不起作用。希望这对您有所帮助:)

您看到了吗?我想指出,如果您使用TkAgg后端,那么您正在tkI see中使用嵌入。所以它把它放到画布上。你知道我将如何将其整合到熊猫数据读取器中吗?