簡體   English   中英

Python matplotlib plot /graph 從起點開始部分刷新

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM