Whether you are using sensors, constantly pulling data from an API, or have files that are updated frequently, you may want to analyze data in real-time.This article will explore a simple way to animate plots using functions via Matplotlib FuncAnimation.
Installing the psutil
library can easily query the current system CPU and memory usage:
pip install psutil
This article will use deques to process data, but you can adapt the example to handle most collections, such as dictionaries, data frames, lists, or others.
Import dependent libraries as follows:
import matplotlib.pyplot as pltimport numpy as npfrom matplotlib.animation import FuncAnimationimport psutilimport collections
Let's start by collecting and storing data.We will define two deques filled with zeros.