मैं एक लाइव एनिमेशन जो मैं करना चाहते को अद्यतन करने के लिए एक्स और वाई अक्ष के दौरान प्रत्येक redraw.
Ive की कोशिश की करने के लिए कई तरीके से इस को हल कर रहे हैं, जो छोड़ दिया, के रूप में टिप्पणी में नीचे दिए गए कोड को
मुझे विश्वास है कि अब इस मुद्दे को उठता है लौटने से लाइन है, जो करने के लिए संबंधित चर कुल्हाड़ी, जबकि FuncAnimation पर कार्य करता चर अंजीर?
import pandas as pd
import time
import matplotlib.pyplot as plt
import matplotlib.animation as animation
global df
df = pd.DataFrame(columns = ['time', 'number'])
global start_time
start_time = time.time()
df['time'] = [1]*40
df['number'] = [1]*40
global counter
counter = 0
while counter<40:
df.iat[counter, 0] = round(((time.time()-start_time)*10))
df.iat[counter, 1] = counter
time.sleep(0.1)
counter = counter+1
def get_data():
global counter
global start_time
global df
df.drop(range(10), axis = 0, inplace=True)
df2 = pd.DataFrame(columns = ['time', 'number'])
list1 = []
list2 = []
for item in range(10):
time.sleep(0.1)
list1.append(round(((time.time()-start_time)*10)))
list2.append(counter)
counter = counter + 1
df2['time'] = list1
df2['number'] = list2
df = df.append(df2, ignore_index = True)
df.reset_index(inplace=True, drop = True)
x_data = df['time']
y_data = df['number']
return x_data,y_data
def get_limits():
global df
x_min = min(df['time'])
y_min = min(df['number'])
x_max = max(df['time'])
y_max = max(df['number'])
return x_min, y_min, x_max, y_max
fig, ax = plt.subplots()
def animate(i):
x_data, y_data= get_data()
x_min, y_min, x_max, y_max = get_limits()
#plt.xlim(x_min, x_max, auto = True)
#plt.ylim(y_min, y_max, auto = True)
ax.set_xlim(x_min, x_max, auto = True)
ax.set_ylim(y_min, y_max, auto = True)
line = ax.plot(x_data, y_data)
#line = ax.plot(x_data, y_data,scalex=True, scaley=True, color="red")
#plt.plot(x,y, scaley=True, scalex=True, color="red")
return line
ani = animation.FuncAnimation(
fig, animate, interval=50, blit=True, save_count=50)
#ani2 = animation.FuncAnimation(ax, animate, interval = 50, blit=True, save_count=50)
plt.show()