【问题标题】:Matplotlib Subplot into Tkinter GUI windowMatplotlib 子图进入 Tkinter GUI 窗口
【发布时间】:2014-09-26 09:27:03
【问题描述】:

我正在开发 Tkinter GUI,我想知道是否可以将 Subplot 放入 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)

这是框架的一部分,没有所有的标签等。我已经将 Canvas 注释掉了我希望 Subplot 去哪里。

【问题讨论】:

标签: user-interface matplotlib tkinter python-3.4


【解决方案1】:

这可能有点晚了,但你应该尝试一下这个

     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 中不起作用。希望这会有所帮助:)

【讨论】:

    猜你喜欢
    • 2016-11-27
    • 2021-12-04
    • 2021-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-23
    • 1970-01-01
    相关资源
    最近更新 更多