简体   繁体   English

在tkinter窗口中重新调整pyplots的大小

[英]Re-sizing pyplots in tkinter windows

I am creating a popup window using tkinter's Toplevel containing a pyplot graph, and I have been trying to re-size the window so that I can stretch the graph horizontally to get some more x resolution. 我正在使用包含pyplot图形的tkinter的Toplevel创建一个弹出窗口,我一直在尝试重新调整窗口的大小,以便我可以水平拉伸图形以获得更多x分辨率。 I haven't had any success in accomplishing this. 我没有取得任何成功。 I have tried to modify the width component of the Toplevel, but it just resized back to the graph size. 我试图修改Toplevel的宽度组件,但它只是调整回图形大小。 Below is my code so far. 以下是我的代码。 Any suggestions on how to make the code better are always welcome. 任何关于如何使代码更好的建议总是受欢迎的。

import matplotlib
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.backends.backend_tkagg import NavigationToolbar2TkAgg
from matplotlib.figure import Figure
import Tkinter as tk

root = tk.Toplevel(width=2000)
f = Figure()
ax = f.add_subplot(111)
zeroy = [0,25]
zerox = [0, 35]
p3 = ax.plot(zerox, zeroy, 'k-')
canvas = FigureCanvasTkAgg(f, master=root)
canvas.show()
canvas.get_tk_widget().grid(row=0)

toolbar = NavigationToolbar2TkAgg(canvas, root)
toolbar.grid(row=1, sticky=tk.W) 
toolbar.update() 
button = tk.Button(root, text='Quit', command = root.destroy)
button.grid(row=2)
root.mainloop()

I am sure that it is something nice and easy, but my googlefu has failed me, and my experiments also failed. 我确信这是好事和容易的事,但我的googlefu让我失望,我的实验也失败了。 Help would be greatly appreciated. 非常感谢帮助。

The answer to my question was contained in the second row. 我的问题的答案包含在第二行。

f = Figure(figsize=(15,9))

Where the 15 is the horizontal component and the 9 is the vertical. 其中15是水平分量,9是垂直分量。

Edit: I discovered this a few minutes after posting my question, and left the question to aid future people. 编辑:我在发布问题后几分钟就发现了这个问题,并将问题留给了未来的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM