失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > python运动目标绘制轨迹_实时轨迹绘制Matplotlib

python运动目标绘制轨迹_实时轨迹绘制Matplotlib

时间:2024-07-17 18:40:03

相关推荐

python运动目标绘制轨迹_实时轨迹绘制Matplotlib

我想用matplotlib绘制轨迹。在我编写的程序的每次迭代中,我都会得到对象的x和y坐标。我想在xy图上画出这个物体的运动。我使用了以下代码:import matplotlib.pyplot as plt

from matplotlib.path import Path

import matplotlib.patches as patches

import time

fig = plt.figure()

ax = fig.add_subplot(111)

ax.set_xlim(-100,100)

ax.set_ylim(-100,100)

plt.ion()

plt.show(block=True)

verts = [

(0, 0), #I'm just assuming two sets of points here. I actually intend to put variables here which I can update in real time.

(27, 0)

]

codes = [Path.MOVETO,

Path.LINETO]

path = Path(verts, codes)

#fig = plt.figure()

#ax = fig.add_subplot(111)

patch = patches.PathPatch(path, facecolor='white', lw=2)

ax.add_patch(patch)

#ax.set_xlim(-100,100)

#ax.set_ylim(-100,100)

plt.draw()

time.sleep(1)

但我所能看到的只是一个有两个轴的空白窗口。是的,我确实改变了代码的顺序以满足我的需要(见注释行),因为为了实时起见,我需要将它放入一个循环中。有人能帮我吗?另外,如果我不使用“patch”,这些线就会变得不可见。有别的办法吗?在

如果觉得《python运动目标绘制轨迹_实时轨迹绘制Matplotlib》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。