[英]Completely update matplotlib figure (not appending data)
编辑:我通过完全省略 matplotlib animation 并在初始化数字之前添加plt.ion()
来使其工作。
我有一个可以将数据发送到我的 PC 的测量设备,我可以使用 Python 读取这些数据。 它每秒发送 100 个数据点。 每次收到这100分,都可以通过调用function来获得。 我想更新图形,再次从 X=0 开始。 数据包含 X 和 Y 数据。 在其他 SO 线程中,我发现matplotlib.animation.FuncAnimation
可以有效地更新图表,但我只找到了将数据附加到图表的示例。
目前,我的图表正在重绘,但它只是绘制新点而没有清除之前的图表,而且速度非常慢(我无法在绘制时拖动 plot window)。 清晰的 function 只给我留下了灰色的 window。 有谁知道这个问题足够快的解决方法? 非常感谢!
我目前的实现:
def plot():
freq = np.linspace(f_start, f_stop, points, endpoint=True)
def update(frame):
#for i in range (iterations - 1):
print(frame)
complex_data = vna.data(0)
plotFigure(figInitProperties, freq, Rect2Pol(complex_data))
time.sleep(2) # Wait for all points to be scanned
ani = anim.FuncAnimation(figInitProperties[2], func=update, frames=(10), repeat=False)
plt.show()
plot()
figInitProperties
返回图形的fig
(大小、标签、轴、刻度等)。
您可以在更新 function 的开头使用ax.clear()
或plt.cla()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.