【问题标题】:Real time trajectory plotting - Matplotlib实时轨迹绘图 - Matplotlib
【发布时间】:2015-02-13 16:47:09
【问题描述】:

我想使用 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)

但我只能看到一个带有两个轴的空白窗口。是的,我确实更改了代码的顺序以满足我的需要(请参阅注释行),因为对于实时,我需要将其置于循环中。有谁可以帮我离开这里吗?另外,如果我不使用“补丁”,线条就会变得不可见。还有其他方法吗?

【问题讨论】:

    标签: python matplotlib plot real-time


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-18
      • 1970-01-01
      • 2016-02-12
      • 1970-01-01
      • 2016-08-05
      • 2023-03-10
      相关资源
      最近更新 更多