#!/usr/bin/python
# coding=UTF-8
# Filename : datatemp.py

from matplotlib.dates import strpdate2num
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
import matplotlib.dates as mdates
#from matplotlib.mlab import load
import numpy as np
from pylab import *
import os, sys

datafile = ('NotasFaltasMec22012.csv')
print 'loading', datafile

times, Notas, Faltas  = np.loadtxt(
    datafile, delimiter=',',
    converters={0:strpdate2num('%d-%b-%y-%H:%M:%S') },
    skiprows=1, usecols=(0,1,2), unpack=True)

fig = figure()
ax1 = fig.add_subplot(211)
ax1.set_title('$\mathbf{Frequ\^{e}ncia}$ em %', color='r')
ax1.bar(times, Faltas, color='r')
ax1.axvspan(*mdates.datestr2num(['05/18/2012', '06/30/2012']), facecolor='g', alpha=0.5)
ax1.autoscale_view(tight='True', scalex=True, scaley=False)
ax1.yaxis.set_label_coords(-0.065, 0.5)
ax1.set_ylim(0,100)
ax1.axhline(y=75, linewidth=1, color='black')
ax1.annotate('linha de 75%', xy=(.29, .81),  xycoords='axes fraction',
                horizontalalignment='center', verticalalignment='center')

for tl in ax1.get_yticklabels():
    tl.set_color('red')

locator   = MultipleLocator(14)
ax1.xaxis.set_major_locator(locator)
setp(gca(), 'xticklabels', [])

datafile = ('NotasFaltasMec22012.csv')
print 'loading', datafile

times, Notas, Faltas  = np.loadtxt(
    datafile, delimiter=',',
    converters={0:strpdate2num('%d-%b-%y-%H:%M:%S') },
    skiprows=1, usecols=(0,1,2), unpack=True)
    
ax3 = fig.add_subplot(212)
ax3.set_title('$\mathbf{Nota\ Acumulada}$', color='b')
ax3.plot_date(times, Notas, 'b-',linewidth=2.0)
ax3.yaxis.set_label_coords(-0.065, 0.5)
ax3.set_ylim(0,10)

for tl in ax3.get_yticklabels():
    tl.set_color('blue')

ax3.autoscale_view(tight='True', scalex=True, scaley=False)
ax3.grid('True')	
# Imprime as datas no eixo x
locator   = MultipleLocator(14)
formatter = mdates.DateFormatter('%d %b')
ax3.xaxis.set_major_formatter(formatter)
ax3.xaxis.set_major_locator(locator)

#  Inclina as datas no eixo x para melhorar apresentacao
fig.autofmt_xdate()
show()