簡體   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