在 python 中将许多信号绘制在一起

问题描述 投票:0回答:1

我正在尝试从多电极数据集绘制许多信号(196)(https://zenodo.org/records/1411883)。我想绘制一些很酷的东西来一起查看所有寄存器。我想要得到类似的东西:

enter image description here

有没有任何 python 包或方法可以建议我遵循来绘制所有这些信息?

我尝试创建子图,但它们太小并且需要太多时间才能生成。

matplotlib plot visualization
1个回答
0
投票

我认为在同一个绘图上绘制 196 个信号有点太多了。

下面是 30 个信号,使用计算的偏移量:

many signals

import matplotlib.pyplot as plt
import numpy as np


def multisignals(t, signals, ax=None):
    if ax is None:
        fig, ax = plt.subplots()
    # Center the signals and add offsets
    sigs = signals - signals.mean(axis=1, keepdims=True)
    offset = np.max(sigs.max(axis=1)[:-1] - sigs.min(axis=1)[1:])
    # Plot the signals
    ax.plot(t, sigs.T + np.arange(len(signals)) * offset)
    # Plots horizontal lines to separate the signals
    for i in range(len(signals) + 1):
        ax.axhline(i * offset - offset / 2, color="k", lw=0.5, alpha=0.3)
    return ax


def create_signals(t, n):
    # Dummy function to generate signals
    freqs = np.random.rand(n) * 3 + 1
    amps = np.random.rand(n) * 3.8 + 0.2
    signals = np.zeros((n, len(t)))
    for i, (freq, amp) in enumerate(zip(freqs, amps)):
        signals[i] = amp * np.sin(2 * np.pi * freq * t)
    return signals


def main():
    t = np.linspace(0, 10, 600)
    n = 30
    signals = create_signals(t, n) + create_signals(t, n) + create_signals(t, n)
    ax = multisignals(t, signals)
    ax.tick_params(left=False, labelleft=False)
    plt.show()


if __name__ == "__main__":
    main()
© www.soinside.com 2019 - 2024. All rights reserved.