May 2019
Intermediate to advanced
542 pages
13h 37m
English
Our first step in updating our data is to create a method that calls psutil.cpu_percent() and updates the deque object:
def refresh_stats(self): usage = psutil.cpu_percent() self.data.append(usage)
To update the chart, we only need to update the data in the series. There are a couple of ways to do this; for example, we could completely remove all the data in the chart and append() new values.
A better approach is to replace() the values, as follows:
new_data = [ qtc.QPoint(x, y) for x, y in enumerate(self.data)] self.series.replace(new_data)
First, we generate a new set of QPoint objects from our deque object using a list comprehension, and then pass the list to the series object's replace() method, which swaps out ...
Read now
Unlock full access