python - Real time DataFrame plot -


i have pandas dataframe updated in while loop , plot in real time, unfortunately did not how that. samplae code might be:

import numpy np matplotlib import pyplot plt matplotlib import animation import time tm datetime import datetime, date, time import pandas pd  columns = ["a1", "a2", "a3", "a4","a5", "b1", "b2", "b3", "b4", "b5", "prex"] df = pd.dataframe() """plt.ion()""" plt.figure() while not true:      = datetime.now()     adata = 5 * np.random.randn(1,10) + 25.     prex = 1e-10* np.random.randn(1,1) + 1e-10     outcomes = np.append(adata, prex)     ind = [now]     idf = pd.dataframe(np.array([outcomes]), index = ind, columns = columns)     df = df.append(idf)     ax = df.plot(secondary_y=['prex'])      plt.show()     time.sleep(0.5) 

but if uncomment """plt.ion()""" many different windows open. otherwise have close window updated plot. suggestions?

you can specify axes plot use instead of creating different axes each time call it. redraw plot in interactive mode can use draw instead of show.

from matplotlib import animation import time tm datetime import datetime, date, time import pandas pd  columns = ["a1", "a2", "a3", "a4","a5", "b1", "b2", "b3", "b4", "b5", "prex"] df = pd.dataframe() plt.ion() fig = plt.figure() ax = fig.add_subplot(111) # create axes.  while true:      = datetime.now()     adata = 5 * np.random.randn(1,10) + 25.     prex = 1e-10* np.random.randn(1,1) + 1e-10     outcomes = np.append(adata, prex)     ind = [now]     idf = pd.dataframe(np.array([outcomes]), index = ind, columns = columns)     df = df.append(idf)     df.plot(secondary_y=['prex'], ax = ax) # pass axes plot.       plt.draw() # draw instead of show update plot in ion mode.      tm.sleep(0.5) 

Comments

Popular posts from this blog

html - height not adding height to a empty div -

Oracle SQL. How to select specific IDs where value of columns specify criteria? -

python - Robot Framework location and name of keyword -