trying to plot histogram on realtime basis with set of data from a sensor using txt file
尝试使用TXT文件从传感器提供的数据绘制柱状图。文件具有连续运行的数据,它应该从第一行获取数据,但它应该排除数据开头的一些值,并绘制图形,然后移动到下一行,希望在实时的基础上做到这一点。尝试了几件事,但没有成功。我得到一个错误,无法将字符串转换为浮点:"27/12/2018-14:35:30"。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | import matplotlib.pyplot as plt import numpy as np import matplotlib with open('load.txt', 'r') as fx: for line in fx: counter = True line = line.split(',') for thing in line: if counter: counter = False else: print(thing) f= np.loadtxt('load.txt', delimiter=',', unpack= True) bins = [0,50,100,150,200] plt.hist(f, histtype = 'bar', bins = bins, rwidth=1, color='c') plt.xlabel('x values') plt.ylabel('y values') plt.title('OPC_N3 Histogram') #plt.legend() plt.show() |
数据:但是它应该排除初始值,例如在第一个数据块中,它应该从第一个0中取值,然后用下一个数据块绘制柱状图作为每个数据块的输出。
27/12/201814:35:30:30,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 0,0,0,0,0,0,6,0,4,60
2018年12月27日-2018-14:36:40,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,74100
2018年12月27日-2018-14:37:51,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0223,60
2018年12月27日-2018-14:39:02,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0130,60
2018年12月27日-2018-14:40:13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0197182
在拆分后添加此行
1 | line=line.apply(lambda x: x[-1:]) |
祝你好运!
正如我所看到的,float的问题是您提供了第一件事情,这应该像我在代码中那样被忽略,您可能想要做的事情是为文件使用线程,但是在这种情况下,您将从第一个文件中删除该行并将其添加到备份文件中,线程处理的最佳方法是允许您根据icly不停止甚至错误都不能停止程序这里有一个类似的问题,您现在有了python多进程/多线程来加速文件复制。
另外,如果您选择答案,请将问题标记为已回答,谢谢:)