使用 python 制作快照图

Making snapshot plots using python

我有一个动态模拟,我正试图在我正在写的一篇论文中对其进行可视化。

我想随着时间的推移获取 'snapshots' 动态,然后将它们全部叠加在同一个 canvas 上,根据时间绘制(对于每个快照)。

类似于此(行走机构):

为了完整性;快照是按一定的固定时间间隔拍摄的,由某种频率预定义。这就是我想效仿的。

这个答案可能需要一些迭代来改进,因为它仍然不完全清楚你的模型看起来如何,你得到什么样的数据等等。但下面是尝试#1,它绘制了一个动态( 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(..)

在这种情况下,绘图会在模型运行时更新,但这当然可以很容易地被更改,例如保存数据并在之后以类似的循环绘制它们。