Ich habe eine Animation in Python und ich möchte ein Zeitlabel hinzufügen, das aktualisiert wird. Ich habe bereits ein NumPy-Array namens Zeit, und so dachte ich, es wäre so einfach wie das Einfügen der Variablen in das Etikett.Animations-Label in Python aktualisieren
fig, ax = plt.subplots()
line, = ax.plot([], lw=2)
time_text = ax.text(0.02, 0.95, '', transform=ax.transAxes)
plotlays, plotcols = [1], ["blue"]
lines = []
for index in range(1):
lobj = ax.plot([], [], lw=2, color=plotcols[index])[0]
lines.append(lobj)
def animate(i):
xlist = [xvals]
ylist = [psisol[i,:].real]
time_text.set_text('time = %0.2f' % time[i])
for lnum, line in enumerate(lines):
line.set_data(xlist[lnum], ylist[lnum])
return lines
ich getroffen habe es von Jake Vanderplas Double Pendulum Tutorial here, und auch ich sah an diesem Stackoverflow post. Während das Programm ausgeführt wird, bleibt der Plotbereich grau. Wenn ich den Textcode auskommentiere, läuft das Programm perfekt und grafisch und animiert. Ich bin mir nicht sicher, was ich sonst noch versuchen sollte.
Danke für jede Hilfe.