0

I followed the tutorial on live graph plot from CSV/TXT file, but when I am running the python program no graph is created, instead, the terminal goes into busy mode until I exit using 'Ctrl+Z'.

For some reason, the animate function in matplotlib is not working for me. Instead I wrote the following code, which is supposed to do the job:

import matplotlib.pyplot as plt

while True:
    pullData = open("data1.csv","r").read()
    dataArray = pullData.split('\n')
    xar = []
    yar = []
    for eachLine in dataArray:
        if len(eachLine)>1:
            x,y = eachLine.split(',')
            xar.append(x)
            yar.append(y)
    plt.plot(xar, yar)
    plt.pause(0.05)

plt.show()

But the above code is not reading the data points from the CSV file properly and generating the wrong graph.

I currently have Python 3.6.5 :: Anaconda, Inc. installed on the system. Could someone help in this, please? Thank you in advance.

1 Answer 1

1

You could use the polt Python package which I developed for this exact purpose of displaying live data.

Supposing you want to display live timeseries of multiple data columns in a CSV file, you could just pipe the live CSV stream (header+live columns) into polt:

(head -n1 myfile.csv; tail -fn0 myfile.csv) | polt add-source -p csv live

polt add-source -p csv live

Explanation

(
head -n1 myfile.csv; # output first line of CSV file (header) 
tail -fn0 myfile.csv # output new CSV data continuously
) | polt \ # pipe the data into polt
    add-source -p csv # tell polt to interpret data as CSV
    live # do the live plotting

If you do not directly want to plot timeseries, you can check the polt Animator documentation for further displaying possibilities.

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome utility!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.