animation - 如何使用 matplotlib 和赛璐珞放置动态图例
问题描述
我正在尝试模拟粒子的运动,并在粒子移动时显示时间戳。如何将时间戳/图例放置在固定位置(比如右上角)?
这是我迄今为止所拥有的:
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')
解决方案
推荐阅读
- python-2.7 - 部署 Angular 7 网站和谷歌应用引擎 API 时的应用 yaml 配置问题
- android - AndroidThings UsbToUart 长时间运行时无法接收数据 [关闭]
- php - 在php中获取没有循环的特定行的特定列
- fastlane - macOS Catalina fastlane nokogiri.bundle 无法打开,因为无法验证其完整性
- android - Android、Google Drive:Google 同意屏幕冻结
- winapi - 在保持相同地址的同时重新映射 MapViewOfFile
- ruby-on-rails - postgresql 的 Bigint 列在我的 Rails 应用程序中不起作用?
- qt - QT 调试器的表达式评估不能评估函数结果?
- wordpress - 如何动态添加特征图像 wordpress
- ruby-on-rails - 使用公寓 gem 的多租户 Rails Active Storage