python - Matplotlib, live plot not responsive -


i have following code below:

the idea have csv file gets updated every few seconds recent price of stock read data program , make ohlc plot updated live after each minute passes.

when run code works fine , plot updates every minute , nicely displays new bar. issue matplotlib figure unresponsive , lags. example if try maximize window freezes , stalls.

i imagine there better way plotting figures responsive , there less lag. how can fix code accomplish this?

i have looked issue , have seen similar live plotting dilemmas solved using ‘blitting’, see here: https://matplotlib.org/api/animation_api.html unsure how work in case candlestick2_ohlc plotting function.

import matplotlib.pyplot plt import matplotlib.animation animation matplotlib.finance import candlestick2_ohlc import csv import time  o=[] h=[] l=[] c=[]  def barplot(ticker_symbol):   data_current_minute=[]  plt.ion()  fig, ax = plt.subplots()   open(tick+".csv", 'r') my_file:      reader = csv.reader(my_file, delimiter=',')      my_list = list(reader)   old_minute=my_list[0][1]   i=0  while i==0:       time.sleep(1)       open(pair+".csv", 'r') my_file:          reader = csv.reader(my_file, delimiter=',')          my_list = list(reader)          print my_list       if len(my_list)>=1:             data_current_minute.append(my_list[0][0])          current_minute=my_list[0][1]       if old_minute != current_minute:           old_minute = current_minute           o.append(data_current_minute[0])          h.append(max(data_current_minute))          l.append(min(data_current_minute))          c.append(data_current_minute[len(data_current_minute)-1])           candlestick2_ohlc(ax,o,h,l,c,width=0.6,colorup='g',colordown='r')          #plt.plot(c)          plt.pause(1)           data_current_minute=[] 


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -