【问题标题】:matplotlib - strange y-axis when plotting multiple lines [duplicate]matplotlib - 绘制多条线时出现奇怪的 y 轴 [重复]
【发布时间】:2019-04-07 04:30:40
【问题描述】:

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

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

似乎这些图是相互堆叠的。

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)

请帮帮我:)

【问题讨论】:

  • 如果注释掉set_major_locator 行会发生什么?
  • 相同的图,但有很多不同的值,你无法在 y 轴上读取任何内容
  • 你能编辑你的帖子并举个例子acc_x让我测试一下吗?

标签: python matplotlib plot data-science


【解决方案1】:

问题在于csv.reader 返回文本,因此绘图没有对值进行排序。 您应该使用intfloat 转换值:

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

【讨论】:

  • 哇。没看到那个:)
猜你喜欢
  • 2022-01-20
  • 1970-01-01
  • 1970-01-01
  • 2018-08-17
  • 2021-11-01
  • 1970-01-01
  • 2019-11-04
  • 1970-01-01
相关资源
最近更新 更多