''' Various way to plot 1D and 2D histograms '''
#Nicolas Enfon - LSIS DYNI - 28/04/2014
from matplotlib.pyplot import *
import numpy as np
from math import factorial as fact

fulldata = 'ToutReadmeAntaresV3_21.txt'
filename = 'iciZiphiuscol1216.txt'
sunname = 'sunrise_sunset_2012.csv'
moonname = 'nonefornow'

#import data
data = np.loadtxt(filename, delimiter=',')
#removes the line if one value is NaN
for i in xrange(len(data[0])):
    data = data[np.logical_not( np.isnan( data[:,i] ) )]

#TODO remove the last '5' in the 14th column
#TODO mettre nuit/jour

#Hist 1D
def hist1dall(data, figx=10, figy=10, bins=100, savename=None):
    figure(figsize=(10,10))
    for i in xrange(len(data[0])):
        subplot(len(data[0]),1,i)
        hist(data[:,i], bins=bins)
	title('data['+str(i)+']')
    if savename != None:
	savefig(savename)

#Hist 2D
def hist2dall(data, figx=10, figy=10, bins=100, savename=None):
    '''plots all the possible pairs of comparison'''
    figure(figsize=(figx,figy))
    combin = lambda k,n: fact(int(n))//(fact(int(k))*fact(int(n-k)))
    index = 1
    for i in xrange(len(data[0]) - 1):
        for j in xrange(i+1, len(data[0])):
	    subplot(combin(2,len(data[0])), 1, index)
	    index += 1
	    H, xedges, yedges = np.histogram2d(data[:,i],data[:,j],bins=bins)
	    imshow(H, interpolation='nearest', origin='low', extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]])
	    title('data['+str(i)+'] VS data['+str(j))
    if savename != None:
	savefig(savename)

