How to animate a graph?
📁 Advanced Python Topics, matplotlib, pip, jupyter
Tell me, is there a way to draw animated graphs in jupyter, like a real-time CPU load graph? I'm trying to monitor server ping response time. I'm looking into matplotlib, but either it can't do that, or I haven't found how:
import subprocessimport refrom matplotlib import pyplot as pltdef ping(adress): p = subprocess.Popen([""ping.exe"",adress], stdout = subprocess.PIPE) out = p.communicate()[0] t = re.search(r'time=(\\d*)',str(out)) This construction is called a "generator". It's a way to create a list (array) filled with values in one line. There is no colon precisely because this is not a for loop, but a generator. Let's break it down in detail:
[i for i in range(51) if i % 2 == 0]or in a more general form:
[expr(variable) for variable in iterable if condition(variable)]Here:
iterable— some object from which you can get elements one by one
Log in to leave an answer
Blogs