#!/usr/bin/env python2.7
# coding: utf-8
import matplotlib
from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvasAgg
from datetime import datetime
import matplotlib.dates as dates
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.image as mpimg

date = [ 734894.994583, 734894.995313, 734894.996042, 734894.997384,
734894.998032 ]
price = [ 17.37, 17.30001, 17.30001, 17.39, 17.39 ]
graphdate = []
for i in date:
   graphdate.append(i)

graph = np.zeros((100,100,3))
fig=Figure(figsize=(5.5,2.4))
pl=fig.add_subplot(111)
image=pl.imshow(graph,aspect="auto",extent=(min(date),max(date),min(price),max(price)))
fig.subplots_adjust(top=0.92,bottom=0.15,left=0.1,right=0.95)

# add plot of value across time
pl.plot_date(zip(graphdate),zip(price),'-',color='blue',lw='1',alpha=1)
matplotlib.rcParams.update({'font.size': 5})

locator = dates.AutoDateLocator()
pl.set_ylim([min(price),max(price)])

pl.tick_params(labelleft=True, labelright=True)
pl.ticklabel_format(axis='y', style='plain', useOffset=False)

period = 298; # duration in seconds for this graph
seconds = dates.SecondLocator(interval=30) # plot by 30-second increment
secondsFmt = dates.DateFormatter('%-I:%M:%S%P',tz=None)
pl.xaxis.set_major_locator(seconds)
pl.xaxis.set_major_formatter(secondsFmt)

labels = pl.get_xticklabels()
for label in labels:
   label.set_rotation(45)

pl.xaxis.grid(which='major',color='white', linestyle='--', linewidth=0.5,
alpha=0.15)
pl.xaxis.grid(which='minor',color='white', linestyle='--', linewidth=0.5,
alpha=0.15)
pl.yaxis.grid(which='major',color='white', linestyle='--', linewidth=0.5,
alpha=0.15)
pl.yaxis.grid(which='minor',color='white', linestyle='--', linewidth=0.5,
alpha=0.15)

canvas=FigureCanvasAgg(fig)
bigName = "sci_formatting_fail.png"   # image name
canvas.print_figure(bigName,dpi=200)       # create date/timestamped file
print "grapher completed"



