繁体   English   中英

实时轨迹图-Matplotlib

[英]Real time trajectory plotting - 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)

但是我只能看到一个带有两个轴的空白窗口。 是的,我确实更改了代码顺序以适合我的需要(请参阅注释行),因为要实时,我需要将其循环。 有人可以帮我从这里出去吗? 另外,如果我不使用“补丁”,则这些行将变得不可见。 还有其他办法吗?

谢谢,我解决了我自己的问题。 使用plt.show()代替plt.show(block = True)。 另外,在代码末尾添加plt.pause(0.05)。 time.sleep()是不必要的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM