【发布时间】:2019-02-06 14:05:52
【问题描述】:
我从麦克风收到一堆实时数据。 一个数据集的长度是 4000,我每秒接收 5 次。
我使用 python2.7 和 matplotlib。要了解数据集:
如果它安静
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -2, 0, -1, 0, 0, 0, -1, 1, -2, 0, -2, -2, -8, -1, -1, 0, -2, -1, -2, -1, -1, -1, 0, -1, 0, -1, 0, -1, -1, -1, -1, -1, 0, -1, 0, -1, -1, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, -1,-1, 0, -1, -4, -1, 0, -1, 2, -1, 0, 2, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, ...]
如果声音很大:
[-372, -37, -157, -143, 93, -212, 304, -225, 432, -177, 450, -79, 351, 40, 159, 147, -77, 213, -296, 222, -440, 173, -467, 77, -366, -41, -161, -147, 90, -215, 308, -225, 435, -175, 446, -77, 351, 42, 167, 147, -70, 210, -296, -166, 456, -76, 374, 34, ...]
我的python脚本:
def plot_data(data):
x = [i for i in range(0, 4000)]
plt.plot(x,data.data)
plt.show()
def listener():
rospy.init_node('listener', anonymous=True)
rospy.Subscriber('/miro/rob01/platform/mics', platform_mics, show_data)
rospy.spin()
if __name__ == '__main__':
listener()
我想绘制数据并在每次获得新数据对象时重新绘制或更新。需要不断更新图表。
你知道这样做的好方法吗?
【问题讨论】:
-
旁注:在 Python 2.7 中,您应该使用
xrange而不是range进行for循环。在这种情况下,您也应该能够只写x=range(4000) -
乍一看,这听起来像是你会使用 Bokeh 或 Plotly 的东西。 matplotlib 相当有限。
-
我强烈反对@MatthewArthur 的评论。 Matplotlib 在某些方面有局限性,主要是 3D 绘图和 Web 集成,但这里都不需要。关于这个问题,
show_data和plot_data是否意味着相同?您是否看过有关使用 matplotlib 进行实时绘图的类似问题?他们在多大程度上没有帮助?
标签: python matplotlib data-science ros