In [5]:
import random
from itertools import count
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
In [6]:
x_vals = []
y_vals = []
In [8]:
plt.style.use('fivethirtyeight')

index = count()

def animate(i):
    x_vals.append(next(index))
    y_vals.append(random.randint(0, 5))
    plt.cla()
    plt.plot(x_vals, y_vals)

#FuncAnimation function for live data plotting,and passing figure, function with changing data and time in ms
anim = FuncAnimation(plt.gcf(), animate, interval=1000)


plt.tight_layout()
plt.show()
#this will plot live plot with changing data on terminal
<Figure size 432x288 with 0 Axes>
In [9]:
#this will create live plot from reading csv
plt.style.use('fivethirtyeight')

index = count()

def animate(i):
    data = pd.read_csv('data.csv')
    x = data['x_value']
    y1 = data['total_1']
    y2 = data['total_2']

    plt.cla()

    plt.plot(x, y1, label='Channel 1')
    plt.plot(x, y2, label='Channel 2')

    plt.legend(loc='upper left')
    plt.tight_layout()


#FuncAnimation function for live data plotting,and passing figure, function with changing data and time in ms
anim = FuncAnimation(plt.gcf(), animate, interval=1000)


plt.tight_layout()
plt.show()
#this will plot live plot with changing data on terminal
<Figure size 432x288 with 0 Axes>