ich diesen Code schrieb ein dynamisches Diagramm mit matplotlib zum Plotten, aber es funktioniert nicht:matplotlib Animation funktioniert nicht
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)
die data.txt Daten sind wie diese:
1,0.8
2,1.4
3,1.4
4,2.6
5,1.5
6,1.6
7,2.4
Ich benutze Python2.7 und die neueste Version von Matplotlib
Bitte achten Sie auf Einrückung, da dies (in Python) Teil der Semantik Ihres Programms ist - es könnte der Fall sein, dass darin Ihr Problem liegt – DAXaholic
Ihr Beispiel funktioniert nicht. Nach 'def animate (i): sollte ein Einzug sein.'. Könnten Sie das bitte korrigieren? –
im Programm ist es in Ordnung, hier, als ich es hier einfügen war es so – pouya