動作しない私はmatplotlibのを使って動的なダイアグラムをプロットするために、このコードを書いたが、それは動作しません:matplotlibのアニメーションが
from matplotlib import style
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
def animate(i):
graph_data = open ('data.txt','r').read()
lines = graph_data.split('\n')
xs = []
ys = []
for line in lines:
if len(line) > 1:
x, y = line.split(',')
# print(x,y)
xs.append(x)
ys.append(y)
# print(xs,ys)
# ax1.clear()
ax1.plot(xs, ys)
ani = animation.FuncAnimation(fig, animate, interval=1000)
data.txtを件のデータがこれらのようなものです:
1,0.8
2,1.4
3,1.4
4,2.6
5,1.5
6,1.6
7,2.4
私はpython2.7とmatplotlibの最新バージョンを使用します
これは(Pythonで)プログラムのセマンティクスの一部であるため、字下げに注意してください - あなたの問題がある場合があります – DAXaholic
あなたの例は機能していません。 'def animate(i):'の後にインデントがあるはずです。これを修正してください。 –
がプログラムのokです。ここに貼り付けたときには – pouya