Making snapshot plots using python
<p>I have a dynamic simulation that I am trying to visualise in a paper that I am writing. </p>

<p>I would like to take 'snapshots' of the dynamics as they progress over time, and then superimpose all of them on the same canvas, plotted against time (for each snapshot). </p>

<p>Similar to this (walking mechanism):</p>

<p><a href="http://i.stack.imgur.com/9VDVx.png" rel="nofollow"><img src="http://i.stack.imgur.com/9VDVx.png" alt="enter image description here"></a></p>

<p>For completeness; the snapshots are taken at some regular interval, predefined by some frequency. This is what I would like to emulate.</p>

<p>This answer might need some iterations to improve since it is still not completely clear how your model looks, what kind of data you get, etc. But below is attempt #1 which plots a dynamic (<em>drunk stick figure</em>) system in time/space.</p>

<pre><code>import matplotlib.pylab as pl
import numpy as np

pl.close('all')

y = np.array([2,1,0]) # y-location of hips,knees,feet
x = np.zeros((2,3))   # x-coordinates of both legs

# Plot while the model runs:
pl.figure()
pl.title('Drunk stick figure', loc='left')
pl.xlabel('x')
pl.ylabel('y')

# The model:
for t in range(10):
    x[:,0] = t  # start (top of legs) progress in x in time
    x[:,1] = x[:,0] + np.random.random(2)  # random location knees
    x[:,2] = x[:,0] + np.random.random(2)  # random location feet

    pl.plot(x[0,:], y[:], color='k')
    pl.plot(x[1,:], y[:], color='r')

    # or, if you want to plot every nth (lets say second) step:
    # if (t % 2 == 0):
    #     pl.plot(..)
</code></pre>

<p><a href="http://i.stack.imgur.com/ufsfz.png" rel="nofollow"><img src="http://i.stack.imgur.com/ufsfz.png" alt="enter image description here"></a></p>

<p>In this case the plot is updated while the model runs, but that could of course easily be changed by e.g. saving the data and plotting them in a similar loop afterwards. </p>

python matplotlib simulate