2013-06-14 7 views
25

は次のようになります。matplotlib.pyplotは以前のプロットを忘れることはありません - どのようにフラッシュ/リフレッシュできますか?あなたは<code>matplotlib.pyplot</code>は私が<code>matplotlib.pyplot</code></p> <p>コードを使用して複数の時間をプロットしようとしています、以前のプロット</p> <p>を「忘れる」ことを得るにはどうすればよい

def plottest(): 
    import numpy as np 
    import matplotlib.pyplot as plt 


    a=np.random.rand(10,) 
    b=np.random.rand(10,) 
    c=np.random.rand(10,) 


    plt.plot(a,label='a') 
    plt.plot(b,label='b') 
    plt.plot(c,label='c') 
    plt.legend(loc='upper left') 
    plt.ylabel('mag') 
    plt.xlabel('element)') 
    plt.show() 

    e=np.random.rand(10,) 
    f=np.random.rand(10,) 
    g=np.random.rand(10,) 


    plt.plot(e,label='e') 
    plt.plot(f,label='f') 
    plt.plot(g,label='g') 
    plt.legend(loc='upper left') 
    plt.ylabel('mag') 
    plt.xlabel('element)') 
    plt.show() 

残念ながら、私は同じプロットを得続けます私が何をしていても(実際に実行して完了した他のコードから)

同様のコードは以前私のために働いていました。

私はこれらの質問を見てきました:

How to "clean the slate"?

Matplotlib pyplot show() doesn't work once closed

(python) matplotlib pyplot show() .. blocking or not?

と無駄にplt.show()plt.clf()plt.closeを使用してみました。

アイデア?

答えて

49

plt.clf() 
plt.cla() 
plt.close() 

を入れた場合は(グラフをリフレッシュする)動作します。ウィンドウのサイズを維持し、より良いパフォーマンスを提供するだけで、図を閉じて再オープンするのではなく、図をクリアするだけです。

9

この現象は、特定のスクリプトを実行した後にのみ発生することが判明しました。これは、質問に似ています。なぜそれが起こるのか分かりません。

私は私ではなく、すべてのplt.show()plt.gcf().clear()を使用するすべてのplt.show()

関連する問題

 関連する問題