0

Python beginner here.

I would like to plot certain columns from .txt datafile (at real time) which I receive over TCP/IP (I am trying to firstly create a simulation on computer (client - server) before receiving this data from data logger which will act as a client)

I load the Data.txt with pandas (I skip the first row because of UTF-8 encoding issues, I also create data frame df to rename the columns - it is sort of a substitute for skipping the first row):

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

Txt = pd.read_csv('Data.txt', sep = '\t', skipinitialspace = True, header = None, skiprows= 1,)
df = pd.DataFrame(Txt).reset_index()
df.columns = [‘Time’,’Temp_in’,’Temp_out’,’Mass flow’,'K content’,'S content',
                         ‘O content’,’viscosity']

print(df)

graph = {'x' : df['Time'],
     'y1' : df[‘Temp_in'],
     'y2' : df[‘Temp_out']}

df2 = pd.DataFrame(graph)
df2.plot('x',y = ['y1','y2'])
plt.show()

How can I plot df where x axis = Time and y axis = Temp_in, Temp_out and K content? I did not include the K content in the code because it has a different axis values.

I am getting following error: TypeError: no numeric data to plot - I think it is caused by Time which is in format HH:MM:SS - I did not have any success trying to convert it.

There will be multiple graph in the future - I would like to plot 3 graph in one window, so my intention is to somehow get a good order in the code. Also, the received files have up to 10 000 rows (at maximum).

Is using such approach with matplotlib the best solution for real-time data receiving and plotting?

Also I would like to do some computing with the data once I receive them.

Thanks

Josh E.
  • 69
  • 1
  • 8
  • Just saw you were printing the data frame; what have you tried with converting the time? – asylumax Jun 04 '20 at 11:55
  • @asylumax I have tried to follow advices from this thread: https://stackoverflow.com/questions/1574088/plotting-time-in-python-with-matplotlib , but to be honest I do not know whether it is applicable to mine data and also to covert the time with `datetime:` : `Time_object = datetime.fromtimestamp(df['Time'])` while plotting `Time_object`. I am not sure whether I should load this object via `for` cycle. – Josh E. Jun 04 '20 at 13:11

0 Answers0