我想从csv文件中水平移动正弦波

时间:2019-06-20 04:47:31

标签: python python-3.x matplotlib tkinter

我有导入CSV文件的代码,可静态打印正弦和余弦波。我只想水平地从右向左移动,间隔一个间隔。我是python的新手

def read_csv_sin():
    lines = []
    print(filename)
    with open(filename, 'r') as f:
            for line in f.readlines():
                l, name = line.strip().split(',')
                lines.append((l, name))
                collect_y = list(map(itemgetter(0), lines))
                collect_y = [i[0] for i in lines[1::]]
                #collect_z = list(map(itemgetter(1), lines))
                #collect_z = [i[1] for i in lines[1::]]

    collect_y = np.array(collect_y, dtype=float)
    collect_y = [float(collect_y) for collect_y in collect_y]

    # *** Plot data from CSV file ***#
    x = np.arange(0, 4*np.pi - 1, 0.1)
    x = np.array(x)

    plt.plot(x, collect_y)
    fig = plt.figure(1)

    tab3 = FigureCanvasTkAgg(fig, master=wave1)
    plot_widget1 = tab3.get_tk_widget()

    plot_widget1.config(width=600, height=210)
    plot_widget1.grid(row=1, column=0, columnspan=3)

    plt.xlabel('x values from 0 to 4pi')
    plt.ylabel('sin(x)')
    plt.title('Plot of sin from 0 to 4pi')
    plt.legend(['sin(x)'])

0 个答案:

没有答案