![](/img/trans.png)
[英]Unable to plot a graph starting from origin (0, 0) with matplotlib in Jupyter Notebook
[英]Python matplotlib plot /graph partial refresh from starting point
抱歉,我对 python 和 matplotlib 有点陌生,所以我不知道我问得是否正确。 到目前为止,我正在绘制图形,在其中收集通过串行端口输入的整数数组并立即刷新整个绘图区域。 现在我想做部分刷新(如果它是正确的词,则为 idk),例如 PPG/ECG 跟踪,一旦线条/跟踪到达绘图区域的末尾,它就会从头开始,类似于此处的示例 [1]: http://theblogofpeterchen.blogspot.com/2015/02/html5-high-performance-real-time.html 。 我确实明白,如果我继续附加串行端口数据并在它到达时立即绘制它会继续向前扩展绘图,但我不知道如何返回起点并逐渐重新绘制它,就像在心电图中一样。
请在这方面提供帮助
谢谢
我在下面使用FuncAnimation
有一个解决方案。
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
from scipy.misc import electrocardiogram
ecg = electrocardiogram()[0:1000]
fig, ax = plt.subplots()
xdata, ydata = [], []
ln, = plt.plot([], [], '-')
# this is repeat length
n = 200
def init():
ax.set_xlim(0, n)
ax.set_ylim(-1, 2)
return ln,
def update(i):
# update xlim of axes
if i % n == 0:
ln.axes.set_xlim(int(i/n)*n, int(i/n)*n+n)
else:
xdata.append(i)
ydata.append(ecg[i])
ln.set_data(xdata, ydata)
return ln,
ani = FuncAnimation(fig, update, frames=1000, init_func=init, blit=True, interval=10, repeat=False)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.