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>Here is a library that deals with real-time plotting/logging data (<a href="https://pypi.python.org/pypi/joystick/" rel="nofollow">joystick</a>), although I am not sure it is working with jupyter. You can install it using the usual <code>pip install joystick</code>.</p>

<p>Hard to make a working solution without more details on your data. Here is an option:</p>

<pre><code>import joystick as jk
import numpy as np

class test(jk.Joystick):
   # initialize the infinite loop decorator
    _infinite_loop = jk.deco_infinite_loop()

    def _init(self, *args, **kwargs):
        """
        Function called at initialization, see the docs
        """
        # INIT DATA HERE
        self.shape = (10, 4) # M, N
        self.data = np.random.random(self.shape)
        self.xaxis = range(self.shape[1])
        ############
        # create a graph frame
        self.mygraph = self.add_frame(
                   jk.Graph(name="TheName", size=(500, 500), pos=(50, 50),
                            fmt="go-", xnpts=self.shape[1], freq_up=5, bgcol="w",
                            xylim=(0, self.shape[1]-1, None, None)))

    @_infinite_loop(wait_time=0.5)
    def _generate_fake_data(self):  # function looped every 0.5 second
        """
        Loop starting with the simulation start, getting data and
        pushing it to the graph every 0.5 seconds
        """
        # NEW (RANDOM) DATA
        new_data = np.random.random(self.shape[1])
        # concatenate data
        self.data = np.vstack((self.data, new_data))
        # push new data to the graph
        self.mygraph.set_xydata(self.xaxis, self.data[-1])

t = test()
t.start()

t.stop()
t.exit()
</code></pre>

<p>This code will create a graph that is auto-updating 5 times a second (freq_up=5), while new data is (randomly) generated every 0.5 seconds (wait_time=0.5) and pushed to the graph for display.</p>

<p>If you don't want the Y-axis to wiggle around, type <code>t.mygraph.xylim = (0, t.shape[1]-1, 0, 1)</code>.</p>

python matplotlib plot graph jupyter-notebook