1

Trying to plot histogram from data provided by a sensor using txt file. The file has continuously running data, It should take the data from first line but it should exclude some values in the start of the data and plot the graph then move to the next line want to do this on realtime basis. Tried few things but didn't work. I get an error could not convert string to float: '27/12/2018-14:35:30'.

    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()

data: but it should exclude the initial values eg. in the first block of data it should take values from the first 0 and so on with the next blocks and plot histogram as the output one by one for each block of data

27/12/2018 14:35: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,29,27,114,1,8,95,231,137,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

27/12/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,78,12,114,1,72,97,93,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,74,100

27/12/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,78,12,114,1,172,97,156,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,223,60

27/12/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,78,12,114,1,1,98,185,126,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,130,60

27/12/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,78,12,114,1,48,98,234,125,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,197,182

Community
  • 1
  • 1
Akash Lad
  • 15
  • 4

2 Answers2

0

Well As I can see, the problem with float is that you givenit a 1st thing, which should be ignored as I did in my code, the thing you might want to do is to use threading for your file, but in that case, you will be removing the line from 1st file and adding it to an a backup file, the best thing about threading is that it allows you to run it basicly nonstop and even errors should not be able to stop the program Here is a similar problem as you have now Python multiprocess/multithreading to speed up file copying

P.S if you choose an answer, please mark question as answered , thank you :)

StyleZ
  • 1,276
  • 3
  • 11
  • 27
0

Add this line after the split

line=line.apply(lambda x: x[-1:])

Good luck man!

ColdSteel
  • 33
  • 4