为什么这段代码会产生如此奇怪的输出?
我希望绘图重叠,这样我就可以看到重叠的数据点。
这些地块似乎是叠在一起的。
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 返回文本,因此绘图不会对值进行排序。 您应该使用 int 或 float :
csv.reader
int
float
for row in reader: data.append(np.array([int(x) for x in row[5:]]))