根据时间绘制Acclerometer数据

时间:2018-02-19 03:27:42

标签: python plot

所以我试图在时间上绘制加速度计数据,我的csv读起来像这样(列 - >时间,x,y,z):

1518999378635,2.275090217590332,8.601768493652344,3.691260576248169
1518999378653,2.38462495803833,8.633491516113281,4.0964789390563965
1518999378658,2.449866771697998,8.506000518798828,4.082113742828369
1518999378667,2.4372973442077637,8.166622161865234,4.016273498535156
1518999378675,1.8381483554840088,8.848969459533691,4.086902141571045
1518999378681,1.1402385234832764,8.762179374694824,4.225766181945801
1518999378688,1.7818846702575684,8.652046203613281,3.6110546588897705
1518999378694,2.076371431350708,8.80467700958252,4.0527849197387695
1518999378700,2.3720552921295166,8.471882820129395,4.120420932769775

我的初始赌注(如下所示!)是使用散布时间作为颜色,但是输出很明显不是很明显。

from numpy import genfromtxt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

if __name__ == "__main__":

    print("Plotting Accelerometer Data")
    acm_data = genfromtxt("acm_data.csv", delimiter=',', names="time, acc_x, acc_y, acc_z")
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')

    x = acm_data["acc_x"]
    y = acm_data["acc_y"]
    z = acm_data["acc_z"]
    c = acm_data["time"]

    ax.scatter(x, y, z, c=c, cmap=plt.hot())
    plt.show()

输出看起来是:

enter image description here

并且不是很容易理解。处理这个问题的最佳方法是什么? 感谢。

2 个答案:

答案 0 :(得分:2)

这样的事情:

import matplotlib.pyplot as plt

x = [0, 1, 2, 3]

x_accel = [5, 6, 3, 4]
y_accel = [2, 7, 6, 8]
z_accel = [1, 2, 3, 4]

plt.subplot(3, 1, 1)
plt.plot(x, x_accel, '.-')
plt.title('A tale of 3 subplots')
plt.ylabel('X acceleration')

plt.subplot(3, 1, 2)
plt.plot(x, y_accel, '.-')
plt.xlabel('time (s)')
plt.ylabel('Y acceleration')

plt.subplot(3, 1, 3)
plt.plot(x, z_accel, '.-')
plt.xlabel('time (s)')
plt.ylabel('Z acceleration')

plt.show()

生成: enter image description here

当然,你必须弄乱你的轴,不要让你的数据显示尽可能清晰。但总的来说,这比你提出的问题要清楚得多。

答案 1 :(得分:1)

嗯,这是我的回答(把它分成3个二维图):

from numpy import genfromtxt
import matplotlib.pyplot as plt
import numpy as np

if __name__ == "__main__":

    print("Plotting Accelerometer Data")
    acm_data = genfromtxt("acm_data.csv", delimiter=',', names="time, acc_x, acc_y, acc_z")
    fig = plt.figure()

    x = acm_data["acc_x"]
    y = acm_data["acc_y"]
    z = acm_data["acc_z"]
    t = acm_data["time"]

    for dat, num, axis in zip((x,y,z), range(311, 314), "XYZ"):
        plt.subplot(num)
        plt.plot(t, dat, ".")
        plt.title("%s-axis" %axis)
    plt.show()

这给了我这个视觉输出:

Visual output

颜色代码更具可读性。

注意:

1)如果要连接它们,请删除“。”或将其更改为“ - ”

2)这是在Python 3.4

3)如果您愿意,还可以在图表的左侧和底部添加标签。