Skip to content

Instantly share code, notes, and snippets.

@pnavarro-algometrics
Created May 19, 2011 17:00
Show Gist options
  • Save pnavarro-algometrics/981227 to your computer and use it in GitHub Desktop.
Save pnavarro-algometrics/981227 to your computer and use it in GitHub Desktop.
Plot prices with time in the x axis
from numpy import *
from matplotlib.pylab import *
import matplotlib.dates as mdates
data = loadtxt('quotes.csv', delimiter=',')
# Epoch time to number (matlab and matplotlib format)
TIMEZONE_CORRECTION = 60.0 * 60 * 5
time = mdates.epoch2num(data[:, 0] / 1000.0 - TIMEZONE_CORRECTION)
bid = data[:, 1]
ask = data[:, 2]
hours = mdates.HourLocator()
hours_fmt = mdates.DateFormatter("%H:%M")
fig = figure(figsize=(12, 8))
ax = fig.add_subplot(1, 1, 1)
ax.plot(time, bid, 'b', time, ask, 'r')
ax.xaxis.set_major_locator(hours)
ax.xaxis.set_major_formatter(hours_fmt)
xlim([min(time), max(time)])
grid(True, color='#babdb6', linestyle='-')
xlabel('time')
ylabel('price')
title('AAPL Quotes 2010-05-21')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment