当我使用 pyplot 时,Tkinter window 改变尺寸或分辨率

Tkinter window changes dimensions or resolution when I use pyplot

第一次发帖,但发现这些论坛对我的 python 学习非常有帮助!

我在调用 plt.plot 时遇到问题,因为它正在调整我的 tkinter window 的大小。我在 python 2.7 和 3.5 中都试过这个问题。

下面只是重现问题的一些示例代码。您甚至不需要为这个问题显示图形,只要您绘制它调整大小的数据就可以重新创建它。

之前

之后

from tkinter import *
import matplotlib.pyplot as plt

x = [1,2,3,4,5]
master = Tk() 
def plotting():
    plt.plot(x)
    #plt.show()



master.minsize(width=450, height=600)
master.wm_title("Tester")

#
y = Button(master, text='START', command=plotting )
y.place(x=230, y=180)

master.mainloop()

在 windows 自定义显示下有一个滚动条用于: "Change the size of text, apps and other items: 150% (Recommended)"

当我将其更改为 100% 时,tkinter window 不再调整大小。

谢谢@R.p.T 试图帮助我!

您可能想先使用 plt.Figure(),而不是使用 plt.plot(x)。更具体地说,plotting()函数可以构造如下。

def plotting():
    fig = plt.Figure()
    ax = fig.add_subplot()
    ax.plot(x)

然后,您可以fig实现功能。