I have a dynamic simulation that I am trying to visualise in a paper that I am writing.
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).
Similar to this (walking mechanism):
For completeness; the snapshots are taken at some regular interval, predefined by some frequency. This is what I would like to emulate.
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 (drunk stick figure) system in time/space.
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(..)
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.