I am trying to recreate a population variance graph in python
In that example, as soon as we start, the function runs immediately to I guess the limit of the environment set by website.
I have managed to create similar graphs, but for animation I am stuck. Below is my code.
import matplotlib.animation as animation
fig, ax = plt.subplots(1,1,figsize=(5,4))
plt.close()
frameRate = 30
global_counter = 0
def animate(i):
ax.clear()
global global_counter
ax.text(0.5,0.5, 'test:{}'.format(global_counter))
global_counter += 1
ani = animation.FuncAnimation(fig, animate, np.arange(1,1000), interval=frameRate)
plt.tight_layout()
from IPython.display import HTML
HTML(ani.to_html5_video())
Output:
The problem is, the execution time is directly proportional to the number of times and then graph is generated. So if 1000 as above or more, it takes considerable time before generating the graph. Looks like it generates all 1000 frames before outputting the graph. I would need about at least 20000 frames this way. Instead, it should be live, and update as long as website is opened or to an upper limit set without compile time compromise.
And next problem is, after 1000, the counter starts all over again. Shouldn't the global counter continue to increase?
I want
- Program to start immediately and then update dynamically like in example I quoted.
- Program to continue increasing counter or not resetting variables after frames count is over. If not matplotlib, seaborn or plotly or any other lib could help here?
I am using Python 3.x in ipython notebook (anaconda environment).