08 Inline view


In [3]:
# Import matplotlib (plotting) and numpy (numerical arrays).
# This enables their use in the Notebook.
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

import sqlite3
in_db = 'in.db'
data_db = 'data.db'
view_db = 'view.db'

# Import IPython's interact function which is used below to
# build the interactive widgets
from IPython.html.widgets import interact

def plot_sine(refresh=True): #, frequency=4.0, grid_points=12):
    """
    Plot discrete samples of a sine wave on the interval ``[0, 1]``.
    """
    
    """"
    conn = sqlite3.connect(view_db)
    c = conn.cursor()
    for row in c.execute('SELECT * FROM vPrice'):
        print row
    conn.close()
    
    
    
    #print refresh
    plot_original = True
    frequency = 4
    grid_points = 12
    x = np.linspace(0, 1, grid_points + 2)
    y = np.sin(2 * frequency * np.pi * x)

    xf = np.linspace(0, 1, 1000)
    yf = np.sin(2 * frequency * np.pi * xf)

    fig, ax = plt.subplots(figsize=(8, 6))
    ax.set_xlabel('x')
    ax.set_ylabel('signal')
    ax.set_title('Aliasing in discretely sampled periodic signal')

    if plot_original:
        ax.plot(xf, yf, color='red', linestyle='solid', linewidth=2)

    ax.plot(x,  y,  marker='o', linewidth=2)
    """
    
    fig1 = plt.figure()
    fig1.suptitle('GBP/USD price')
    fig1.autofmt_xdate()

    ax1 = fig1.add_subplot(1,1,1)
    
    data = []
    x = []
    y = []
    conn = sqlite3.connect(view_db, detect_types=sqlite3.PARSE_COLNAMES)
    c = conn.cursor()
    #df = pd.read_sql("SELECT count(*), status from iPrice group by status",conn) #,conn,parse_dates={'date':'%Y-%m-%d'})
    results = c.execute('SELECT  date as "[timestamp]", price from vPrice ') 
    #print results
    for row in results:
        #print row[0], row[1]
        #print type(row[0])
        d = row[0]
        #dt = datetime.datetime.strptime(d, '%Y-%m-%d %H:%M:%S.%fZ')
        
        x.append(row[0])
        y.append(row[1])
    conn.close()

    ax1.clear()
    ax1.plot(x,y)
    #ax1.legend(loc='upper left')


# The interact function automatically builds a user interface for exploring the
# plot_sine function.
interact(plot_sine, refresh=True)#, frequency=(1.0, 22.0, 0.5), grid_points=(10, 16, 1), );



In [ ]:


In [ ]: