аватар question@mail.ru · 01.01.1970 03:00

How to animize the schedule?

Tell me, is it possible to draw animated graphs in Jupyter, such as the processor loading schedule in real time? I'm trying to monitor the server response time to the ping. I deal with MatPlotlib, but it doesn’t know how, or I didn’t find it:

   Import  SUBPROCESS  Import  Re  from  matplotlib  import  pyplot  as  plate  def   ping  ( adress ):  p = subprocess.popen ([ "Ping.exe" ", adress], stdout = subprocess.pipe)  out = p.communicate () [ 0 ]  t = re.search ( r'Time = (\ d*) ',  str  (out))  time = t. grap (). Replace (' time = ',  '' )  if  t  else   '' 0 '   retu  (Time) x = [ 0 ] %matplotlib inline  for  i  in   ( 0 ,  10 ):  x.ppend (ping (
                            
                            
                        
аватар answer@mail.ru · 01.01.1970 03:00

You can do this:

   import  psutil  from  datetime  Import  DATETIME  as  dt  from  collections  Import  deque  Import  matplotlib.pyplot  as  plastic  from  matplotlib.dates  import  Date2num  Import  matplotlib.animation  as  animation%matplotlib notebookn =  0 ], maxlen = n) fig, AX = PLT.SUBPLOTS (fIGSIZE = ( 8 ,  3 )) line, = Ax.plot_date (x, y, marker =  "" "" ") ax.spines [ '"LEFT' ]. Set_visible ( false ) ax.spines [ '" bottom' ]. Set_visible ( false ) ax.spines [ 'top' ]. Set_visible ( false ) ax.spines [ 'right' ]. Set_visible ( false )   def   get_data  ():  # retu ping ('ya.ru')    retu  psutil.cpu_percent ( de   animate  ( i ):  x.ppend (date2num (dt.now ())  y.ppend (get_data ())  ax.relim (visible_only =  true )  Ax.autoscale_View ( true )  line.set_data (x, y)  Ax.fill_between (x, - 0.5 ,,, y, color =  'Lightgrey' )   retu  line, ani = animation.funcanimation (fig, anamate, interval =  300 )  #ani.save ("" d: /temp/test.gif "", writer = 'imagemagick', fps = 10)  plt.show ()     

result:

Latest

Similar