def animate(i): data = load_ticker_data(conn, ['usd'],range=[ST,EN]).tail(100) cols = ['usd','usd_l_band','usd_u_band'] data = data[cols] for lnum, line in enumerate(lines): line.set_ydata(data[[cols[lnum]]]) # update the data line.set_xdata(data.index.values) line.axes.relim() line.axes.autoscale_view() plt.legend() return lines,
plt.ion() st = datetime.datetime(2016, 2, 18, 10, 30) en = datetime.datetime(2020, 2, 15, 20, 0) def update_line(line, data, symbol): line.set_xdata(data.index) line.set_ydata(data[[symbol]]) return line #u_band_line, = ax1.plot(data[['usd_u_band']]) #l_band_line, = ax1.plot(data[['usd_l_band']]) fig = plt.figure() ax1 = fig.add_subplot(111) data = load_ticker_data(conn, ['usd','eur'], range=[st,en]) price_line, = ax1.plot(data[['usd']]) plt.show() while True: data = load_ticker_data(conn, ['usd','eur'], range=[st,en]) line = update_line(price_line, data, 'usd') ax1.relim() ax1.autoscale_view() plt.draw() plt.pause(2)
""" from trader_data_prep import load_ticker_data import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation import sqlite3 import datetime ST = datetime.datetime(2016, 2, 18, 10, 30) EN = datetime.datetime(2020, 2, 15, 20, 0) fig, ax = plt.subplots() plt.style.use('ggplot') conn = sqlite3.connect('data/trackerdata.db') data = load_ticker_data(conn, ['usd','eur'],range=[ST,EN]) def animate(i): data = load_ticker_data(conn, ['usd'],range=[ST,EN]).tail(100) cols = ['usd','usd_l_band','usd_u_band'] data = data[cols] for lnum, line in enumerate(lines): line.set_ydata(data[[cols[lnum]]]) # update the data line.set_xdata(data.index.values) line.axes.relim() line.axes.autoscale_view() plt.legend() return lines, # Init only required for blitting to give a clean slate.