0

正如您在此处(视频)中看到的那样,有 2 个动画情节。

让我们将 3 个字符串称为图 1,底部图 2。

图 1 中的 3 个字符串水平向左流动。

我怎样才能使情节 2 流向相同的方向?

def animate(i):
    global frames, line1, line2, line3, scaloaxe

    if frames is not None:
        line1.set_ydata(frames.tail(100)['r'])
        line2.set_ydata(frames.tail(100)['g'])
        line3.set_ydata(frames.tail(100)['b'])
        
        scaloaxe.set_data(frames.tail(100)[['r','g','b']])
    
    frames = fetch_data()
    return line1,line2,line3, scaloaxe
fig, ax = plt.subplots(nrows=2, ncols=1, sharex=False, sharey=False, figsize=(9.5, 8))

printed = False

def draw_lines(ax,time, r,g,b):
    line1, = ax.plot(time, r, 'r-')
    line2, = ax.plot(time, g, 'g-')
    line3, = ax.plot(time, b, 'b-')
    return line1, line2, line3

def draw_scalogram(ax, data, scales, wavelet):
    coeffs, freqs = pywt.cwt(data, scales, wavelet = wavelet)
    scaled_coeffs = np.interp(coeffs, (coeffs.min(), coeffs.max()),(0.0, 1.0))

    if printed == False:
      print('scaled_coeffs.shape = {}'.format(coeffs.shape))
        
    # create scalogram
    scaloaxe = ax.imshow(scaled_coeffs, cmap = 'coolwarm', aspect = 'auto')  #gist_rainbow
    
    return scaloaxe

line1, line2, line3 = draw_lines(ax[0], time_arr, r,g,b)

wavelet = 'morl' # mother wavelet, gaus1,morl
scaloaxe = draw_scalogram(ax[1], frames[['r','g','b']], time_arr, wavelet)

plt.ion()
ani = FuncAnimation(plt.gcf(), animate, interval=1, blit=True, save_count=sys.maxsize)        
4

0 回答 0