matplotlib-打印多条线时奇怪的y轴 [英] matplotlib - strange y-axis when plotting multiple lines

查看:39
本文介绍了matplotlib-打印多条线时奇怪的y轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

看起来这些地块堆叠在一起。

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)

请帮帮我:)

推荐答案

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

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

这篇关于matplotlib-打印多条线时奇怪的y轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆