パーティクルの動きに合わせてタイム スタンプを表示して、パーティクルの動きをシミュレートしようとしています。タイムスタンプ/凡例を固定位置 (右上隅など) に配置するにはどうすればよいですか?
これは私がこれまでに持っているものです:
import numpy as np
from matplotlib import pyplot as plt
from IPython.display import Image, Video
from celluloid import Camera
m1, m2, v0 = 1, 1, 10 # masses, vel ini
x1, y1, x2, y2 = 1, 1, 100, 1 # coordinates
fig = plt.figure()
cam = Camera(fig)
def xf(t):
return x1 + v0*t
def xf2(t): # After the collision
v = m1*v0/(m1+m2) # Conservation of momentum
return x2 + v*t
for t in range(20):
if xf(t) < x2:
plt.plot(xf(t), y1, 'ro', label = str(t))
plt.plot(x2, y2, 'bo')
plt.legend()
cam.snap()
anim = cam.animate()
anim.save('momentum.gif', writer = 'imagemagick')
Image('momentum.gif')