python - 绘制关于时间的加速度计数据

标签 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

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

最佳答案

像这样:

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

当然,您必须弄乱您的坐标轴以及不让您的数据呈现尽可能清晰的内容。但总的来说,这比您问题中发布的内容要清楚得多。

关于python - 绘制关于时间的加速度计数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48859161/

相关文章:

python - 在 Django 中使用 formset_factory

Python 多处理 - 线程池数量不乘以池数量

python - 如何将此 NetHack 函数移植到 Python?

python - Spark 可以从 pyspark 访问 Hive 表,但不能从 spark-submit

r - 使用来自 Zoo 的 as.yearmon 修改 ggplot2 中的绘图

python - 控制 Tkinter 中滚动条的位置

r - 如何重新投影诸如 "wrld_simpl"之类的 map ?

R igraph 部分填充的顶点

r - 在 R 中绘制错误椭圆

c++ - 图形可视化(提升图)