Aug-21-2017, 08:26 AM
Hi,
I am trying to add a feature to a python script written by someone else who used to work at the same company as me. I am by no means a python expert but I have a general understanding.
The software basically looks at a serial input string, and logs this value to a CSV file, and also shows a live trend graph of the value. What I now need to do is add a button to the GUI which generates a graph of the contents of the CSV file.
I have managed to add the button, and I have entered the code to take the values from the CSV file, this works fine with a test file (two columns of numbers). The problem I have is, that the "real" value which will be logged into my CSV file is a value in metric tonnes, the way the original python script is written is that it stores the values in the CSV file as a number with a T unit at the end. So when i try and plot using matplotlib I get an error as it isn't a numeric value. For example my CSV file may look like this (where the first value is time):
16:10:24,1.00T
16:10:25,1.10T
16:10:26,1.15T
16:10:27,1.16T
16:10:28,1.14T
Can anybody tell me how I can generate a graph using matplotlib which will ignore the T unit notation in the CSV file?
This is my current code:
def graph(self):
x,y = np.loadtxt('test.csv', delimiter=',', unpack=True)
plt.plot(x,y)
plt.xlabel('Time')
plt.ylabel('Load Value')
plt.title('Logged Load\n')
plt.show()
Thanks
I am trying to add a feature to a python script written by someone else who used to work at the same company as me. I am by no means a python expert but I have a general understanding.
The software basically looks at a serial input string, and logs this value to a CSV file, and also shows a live trend graph of the value. What I now need to do is add a button to the GUI which generates a graph of the contents of the CSV file.
I have managed to add the button, and I have entered the code to take the values from the CSV file, this works fine with a test file (two columns of numbers). The problem I have is, that the "real" value which will be logged into my CSV file is a value in metric tonnes, the way the original python script is written is that it stores the values in the CSV file as a number with a T unit at the end. So when i try and plot using matplotlib I get an error as it isn't a numeric value. For example my CSV file may look like this (where the first value is time):
16:10:24,1.00T
16:10:25,1.10T
16:10:26,1.15T
16:10:27,1.16T
16:10:28,1.14T
Can anybody tell me how I can generate a graph using matplotlib which will ignore the T unit notation in the CSV file?
This is my current code:
def graph(self):
x,y = np.loadtxt('test.csv', delimiter=',', unpack=True)
plt.plot(x,y)
plt.xlabel('Time')
plt.ylabel('Load Value')
plt.title('Logged Load\n')
plt.show()
Thanks