Real-time update of a Matplotlib graph
In this section, we will present a simple application—a CPU usage monitor, where we will update the Matplotlib graph in real-time (once every second over a period of 30 seconds).
As there are several indicators of CPU usage in a modern operating system, we decided to restrict our graph to the four main ones:
user: The time consumed by processes executed by the users of the machine
nice: The time consumed by processes executed by users but with a lower priority
system: The time consumed by system tasks
idle: The time consumed waiting for something to execute
The ignored indicators contribute for just a minimal part of the CPU usage, so their exclusion doesn't disturb the validity of the example.
Of those four indicators, what we will plot is the percentage of each of them against the total CPU usage.
Here we start:
import sys from PyQt4 import QtGui
These are the modules for command-line parameters and for Python bindings of the QtGui
submodule.
from...