'Why the view doesn't change with the new data that plotted by FuncAnimation?
I am plotting some data, but see nothink. If you zoom out, you will find, that the data is plotted on other side of fig, and the view doesn't...automatically changed for be able to see data. Could someone help me, please?
from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation
fig = plt.figure()
ax = fig.add_subplot()
line, = ax.plot([],[])
x = []
y = []
def animate(i):
x.append(i)
y.append((-1)**i)
line.set_data(x, y)
return line,
anim = FuncAnimation(fig, animate, frames=200, interval=100, blit=True)
plt.show()
Solution 1:[1]
As per https://stackoverflow.com/a/7198623/1008142, you need to call the axes relim and autoscale_view methods.
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.animation import FuncAnimation
fig = plt.figure()
ax = fig.add_subplot()
line, = ax.plot([],[])
x = []
y = []
def animate(i):
x.append(i)
y.append((-1)**i)
line.set_data(x, y)
ax.relim()
ax.autoscale_view()
return line,
anim = FuncAnimation(fig, animate,
frames=200, interval=100, blit=True)
plt.show()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rory Yorke |
