2016-03-07 12 views
8

私はpythonとstackoverflowの両方に新しいので、matplotlibの例を紹介します。私は同じ問題でstackoverflowのpreviously unanswered questionを見つけることができましたが、この問題の解決策を探しました。matplotlibのアニメーションがスパイダーで動作しない

基本的には、例のコードをmatplotlibにコピーしました。例えば:

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.animation as animation 
def data_gen(t=0): 
    cnt = 0 
    while cnt < 1000: 
     cnt += 1 
     t += 0.1 
     yield t, np.sin(2*np.pi*t) * np.exp(-t/10.) 
def init(): 
    ax.set_ylim(-1.1, 1.1) 
    ax.set_xlim(0, 10) 
    del xdata[:] 
    del ydata[:] 
    line.set_data(xdata, ydata) 
    return line, 

fig, ax = plt.subplots() 
line, = ax.plot([], [], lw=2) 
ax.grid() 
xdata, ydata = [], [] 


def run(data): 
    # update the data 
    t, y = data 
    xdata.append(t) 
    ydata.append(y) 
    xmin, xmax = ax.get_xlim() 

    if t >= xmax: 
     ax.set_xlim(xmin, 2*xmax) 
     ax.figure.canvas.draw() 
    line.set_data(xdata, ydata) 

    return line, 

ani = animation.FuncAnimation(fig, run, data_gen, blit=False, interval=10, 
          repeat=False, init_func=init) 
plt.show() 

私は両方のアナコンダ2(のpython 2.7)& 3(のpython 3.5)で、様々なアニメーションの例を実行した、との両方のアニメーションなしで私に空白のプロットを与えます。しかし、各アニメーションはEnthought Canopyで完全に機能します。

スパイダーを使用すると何か簡単なことがありますか?

答えて

9

IPythonコンソールでアニメーションを実行するには、バックエンドを変更する必要があります。あなたはアニメーションの前に%matplotlib qtコマンドを実行することでそれを行うことができます。

このコマンドを毎回使用したくない場合は、あなたがに行くことができます: Tools > Preferences > IPython Console > Graphics > Backend"Automatic""Inline"からそれを変更します。

更新:2018年2月、これは現在Pythonで表示されています。[環境設定]ウィンドウでは、ウィンドウのLHペインで[IPythonコンソール]を選択します。 Graphicsタブを選択し、そこにバックエンドがあります。

詳細はthisをご覧ください。

+1

完璧、ありがとうございます!十分な担当者がいるとすぐに私はアップ・アップをします。 – Medalgardr

+0

'%matplotlib qt5'が私のために働いていました。 – cjorssen

関連する問題