2016-04-05 91 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模塊編碼蟒蛇)。