python 读取csv文件数据,然后通过plot绘图。
#!/bin/bash python
import csv
import numpy as np
from matplotlib import pyplot as plt
col_types = [float, float, float, float, float, float, float]
with open('/home/syy001/Desktop/a.csv') as f:
f_csv = csv.reader(f)
headers = next(f_csv)
pos_x,pos_y,pos_z,roll,pitch,yaw = [],[],[],[],[],[]
index = 0
for row in f_csv:
row = tuple(convert(value) for convert, value in zip(col_types, row))
pos_x.append(row[0])
pos_y.append(row[1])
pos_z.append(row[2])
roll.append(row[3])
pitch.append(row[4])
yaw.append(row[5])
index += 1
x_len = index * 0.1
t = np.arange(0, x_len, 0.1)
# fig=plt.figure(dpi=128, figsize=(10, 6))
plt.plot(t, pos_x, color="green", label="angular_x")
plt.plot(t, pos_y, color="red", label="angular_y")
plt.plot(t, pos_z, color="blue", label="angular_z")
# plt.plot(t, roll, color="yellow", label="acc_x")
# plt.plot(t, pitch, color="skyblue", label="acc_y")
# plt.plot(t, yaw, color="black", label="acc_z")
plt.show()