代码之家  ›  专栏  ›  技术社区  ›  Appyx

matplotlib-打印多条直线时奇怪的y轴[重复]

  •  1
  • Appyx  · 技术社区  · 6 年前

    为什么这段代码会产生如此奇怪的输出?

    我希望绘图重叠,这样我就可以看到重叠的数据点。

    这些地块似乎是叠在一起的。

    def read_csv(name):
        file = open(folder+name,newline='')
        reader = csv.reader(file,delimiter=";")
        data = []
        for row in reader:
            data.append(np.array(row[5:]))
        file.close()
        return data
    
    
    def setup_plotting():
        fig = plt.figure()
        ax = fig.add_subplot(111)
        ax.xaxis.set_major_locator(plt.MaxNLocator(10))
        ax.yaxis.set_major_locator(plt.MaxNLocator(10))
        return ax
    
    
    acc_x = read_csv("acc_x.csv")
    
    ax=setup_plotting()
    
    for entry in acc_x:
        ax.plot(entry)
    

    enter image description here

    请帮帮我:)

    1 回复  |  直到 6 年前
        1
  •  2
  •   agold    6 年前

    问题是 csv.reader 返回文本,因此绘图不会对值进行排序。 您应该使用 int float :

    for row in reader:
            data.append(np.array([int(x) for x in row[5:]]))