Hi, I am trying to plot live data reading them from a txt file. The interesting thing is that it works fine without the animate function and I am not sure what is going on when I introduce this function. The code is appended below.

from datetime import datetime
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.animation as animation
from matplotlib import style

style.use('fivethirtyeight')
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1, axisbg = 'white')
#rect = fig.patch

def animate(i):
    readFile = open ('CoolTerm Capture 2016-06-03 00-36-52.txt', 'r')
    sepFile = readFile.read().split('\n')
    xs=[]
    ys=[]
    for idx, plotPair in enumerate(sepFile):
        if idx > 1:
            xAndY = plotPair.split(',')
            time_string = xAndY[0]
            time_value = datetime.strptime(time_string, '%Y-%m-%d %H:%M:%S')
            print time_string
            ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))
            ax1.plot(xs, ys)
            plt.title("PT100 temperature sensor")
            plt.xlabel('TIME')
            fig.autofmt_xdate(rotation=45)
            ani = animation.FuncAnimation(fig, animate, interval = 1000)
            plt.show()

Recommended Answers

All 3 Replies

What error message(s) are you getting?

It looks to me this,print time_string, could be a problem.
Try print (time_string).

Thank you, but I have solved the problem. Thanks much!

Please remember to mark this solved. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.