Plot dynamically changing graph using matplotlib in Jupyter Notebook
<p>I have a M x N 2D array: ith row represents that value of N points at time i. </p>

<p>I want to visualize the points [1 row of the array] in the form of a graph where the values get updated after a small interval. Thus the graph shows 1 row at a time, then update the values to next row, so on and so forth. </p>

<p>I want to do this in a jupyter notebook. Looking for reference codes. </p>

<p>I tried following things but no success:</p>

<p><a href="http://community.plot.ly/t/updating-graph-with-new-data-every-100-ms-or-so/812" rel="nofollow">http://community.plot.ly/t/updating-graph-with-new-data-every-100-ms-or-so/812</a></p>

<p><a href="https://pythonprogramming.net/live-graphs-matplotlib-tutorial/" rel="nofollow">https://pythonprogramming.net/live-graphs-matplotlib-tutorial/</a></p>

<p><a href="http://stackoverflow.com/questions/5618620/create-dynamic-updated-graph-with-python">Create dynamic updated graph with Python</a></p>

<p><a href="http://stackoverflow.com/questions/11371255/update-lines-in-matplotlib">Update Lines in matplotlib</a></p>

<p>In addition to @0aslam0 I used code from <a href="http://jakevdp.github.io/blog/2013/05/12/embedding-matplotlib-animations/" rel="nofollow">here</a>. I've just changed animate function to get next row every next time. It draws animated evolution (M steps) of all N  points.</p>

<pre><code>from IPython.display import HTML
import numpy as np
from matplotlib import animation
N = 5
M = 100
points_evo_array = np.random.rand(M,N)

# First set up the figure, the axis, and the plot element we want to animate
fig = plt.figure()
ax = plt.axes(xlim=(0, M), ylim=(0, np.max(points_evo_array)))
lines = []

lines = [ax.plot([], [])[0] for _ in range(N)]

def init():    
    for line in lines:
        line.set_data([], [])
    return lines

def animate(i):
    for j,line in enumerate(lines):
        line.set_data(range(i), [points_evo_array[:i,j]])
    return lines

# call the animator.  blit=True means only re-draw the parts that have changed.
anim = animation.FuncAnimation(fig, animate,np.arange(1, M), init_func=init, interval=10, blit=True)

HTML(anim.to_html5_video())
</code></pre>

<p>Hope it will be useful</p>

python matplotlib plot graph jupyter-notebook