Matplotlib Tutorial (Part 9): Plotting Live Data in Real-Time
Why Stack Overflow recommends it
Stack Overflow users link it when answering or asking about live-updating Matplotlib charts driven by a growing CSV file, and often reuse its FuncAnimation pattern.
Recommended by 1 people across 1 different months, 2019 to 2021.
What it is
Part 9 of Corey Schafer's Matplotlib tutorial series in Python. It shows how to plot live data in real time with FuncAnimation by repeatedly reading a CSV file that is being updated and redrawing the chart as new values arrive.
What people said
Recommends B. Okba · 2019-12 · Stack Overflow · on “Update chart every time a point added to CSV file - python”
I just found a solution, thanks to my hero Corey Schafer and his useful tutorial on YouTube : [this video] import pandas as pd import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation plt.style.use('fivethirtyeight') def animate(i): data = pd.read_csv('data.csv') x = data['x_values'] y1 = data['y1_values'] y2 = data['y2_values'] plt.cla() plt.plot(x, y1, label='Channel 1') plt.plot(x, y2, label='Channel 2') plt.legend(loc='upper left') plt.tight_layout() ani = FuncAnimation(plt.gcf(), animate, interval=1000) plt.tight_layout() plt.show()
Cites Bill · 2019-09 · Stack Overflow · on “Why do you have to instantiate the matplotlib.animation.FuncAnimation for it to work?”
So I was following Corey Schafer's video tutorial link [this video] and got confused as to why we need to create a variable for the FuncAnimation Class. Basically why I need to do this ani = FuncAnimation(plt.gcf(), animate,interval=1000) instead of this FuncAnimation(plt.gcf(), animate,interval=1000) The code works only if I create the variable,and I am just confused as to why we need create it in the first place, especially since it is not used. All the other code examples Ive seen that use the FuncAnimation class also set it to a variable.If I could get some clarification on why its necessary it would be greatly appreciated. import random from itertools import count import pandas as pd import
Cites n1colas.m · 2020-04 · Stack Overflow · on “Plot custom data with Tensorboard”
If you really want to use tensorboard you can start looking at tensorflow site [LINK] and this datacamp tutorial [LINK] on tensorboard. With tensorflow you can use summary.scalar to plot your custom data (as the example), no need for particular format, as the summary is taking care of that, the only condition is that data has to be a real numeric scalar value, convertible to a float32 Tensor. import tensorflow as tf import numpy as np import os import time now = time.localtime() subdir = time.strftime("%d-%b-%Y_%H.%M.%S", now) summary_dir1 = os.path.join("stackoverflow", subdir, "t1") summary_writer1 = tf.summary.create_file_writer(summary_dir1) for cont in range(200): with summary_writer1.a
Cites user34755 · 2021-06 · Stack Overflow · on “Python Realtime Plotting from csv file”
This code I get from a GitHub Link here [LINK] . I used the data_gen code to generate random numbers and continually write these numbers into the CSV file. Then, I used the code inside snippets.txt to do real-time plotting. I am using the Colab environment to run the two codes and both in the same directory. The issue I am facing is that the code is not shown the plot in real-time, instead, it plots the data that is being saved in the CSV file after I interrupt the data_gen code. Here is the two code: Frist Code: # data_gen code import csv import random import time import matplotlib.pyplot as plt x_value = 0 total_1 = 1000 total_2 = 1000 fieldnames = ["x_value", "total_1", "total_2"] with op