2016-04-05 92 views
0

如何删除或关闭图形?如何删除或关闭matplotlib中的图形?

我已经定义了一个绘制图形的函数。但是,无论何时我更改变量并关闭matplotlib窗口并绘制新图形,上一个图形都不会被删除。下面是我的程序:

def graphforcevsmass(): 

global velocityvalue 
global radiusvalue 

for i in range(101): 
    j = i * float(int(velocityvalue) ** 2/int(radiusvalue)) 

    x.append(i) 
    y.append(j) 

plt.plot(x, y) 
plt.draw() 

在我的计划,我用了一个按钮来激活上面的函数和变量将取决于在Tkinter的窗口尺度改变。

+0

你的意思是关闭一个嵌入了matplotlib图的tkinter窗口? –

+0

是的,我的意思是关闭嵌入了matplotlib图形的tkinter窗口。 –

回答

1

一种方式做这将是绘制新的变量之前使用

plt.clf() # Clear figure 

(我在enthought树冠使用的Tkinter和matplotlib模块编码蟒蛇)。