##################################
#                                #
# Last modified 5/6/2009         # 
#                                #
# Georgi Marinov                 #
#                                # 
##################################

import matplotlib
matplotlib.use('Agg')

from pylab import *
import matplotlib.axes 
import matplotlib.numerix as N
from matplotlib import *
import matplotlib.colorbar 
import matplotlib.patches
from matplotlib.lines import Line2D
from matplotlib.patches import Rectangle 


try:
	import psyco
	psyco.full()
except:
	pass

import sys

#if len(sys.argv) < 3:
#    print 'usage: python %s listofallgenes chromosome expressiondata outputPictureName' % sys.argv[0]
#    sys.exit(1)

outfilename = sys.argv[1]

F = gcf()
DPI = F.get_dpi()
F.set_figsize_inches(15, 10)

#ax1 = pylab.axes([0.05, 0.85, 0.80, 0.10])
ax2 = pylab.axes([0.9, 0.05, 0.05, 0.90])


mycmdata1 = {'red' : ((0., 0., 0.), (0.5, 0.9, 0.9), (1., 1., 1.)),
             'green': ((0., 0., 0.), (1., 0., 0.)),
             'blue' : ((0., 0., 0.), (1., 0., 0.))}
cmap = matplotlib.colors.LinearSegmentedColormap('mycm', mycmdata1)

#cdict = {'red': ((1.0, 1.0, 1.0), (0.45, 0.0, 1.0), (1.0, 1.0, 1.0)),
#         'green': ((1.0, 1.0, 1.0), (0.35, 1.0, 0.0), (1.0, 1.0, 1.0)),
#         'blue': ((1.0, 1.0, 1.0), (0.35, 0, 0), (1.0, 1.0, 1.0))}

cdict = {'red': ((0.0, 1.0, 1.0), (0.40, 0.0, 1.0),(1.0, 1.0, 1.0)),
         'green': ((0.0, 1.0, 1.0), (0.30, 1.0, 0.0), (1.0, 1.0, 1.0)),
         'blue': ((0.0, 0.0, 0.0), (0.35, 0.0, 0.0), (1.0, 0.5, 1.0))}


my_cmap = matplotlib.colors.LinearSegmentedColormap('my_colormap',cdict,256)


#cmap = cm.RdYlBu_r
norm = colors.Normalize(vmin=-10, vmax=10)
#cb1 = colorbar.ColorbarBase(ax1, cmap=cmap, norm=norm, orientation='horizontal')
cb2 = colorbar.ColorbarBase(ax2, cmap=my_cmap, norm=norm, orientation='vertical')





#matplotlib.patches.Rectangle((0.1,0.1),width=5, height=12,fill=1,facecolor=0.4,visible = True)
#rect = F.figurePatch # a rectangle instance
#rect.set_facecolor('goldenrodyellow')
ax1 = F.add_axes([0.05, 0.8, 0.8, 0.05],)
ax2 = F.add_axes([0.15, 0.8, 0.002, 0.05])
ax1.set_xlabel('Chr1', size='small')
ax2.set_xlabel('', size='x-small')
ax1.set_ylabel('', size='x-small')
ax2.set_ylabel('', size='x-small')

ticklocs = []
ax1.set_yticks(ticklocs)
ax1.set_xticks(ticklocs)
ax2.set_yticks(ticklocs)
ax2.set_xticks(ticklocs)





#ax1.set_yticklabels()
#for label in ax2.xaxis.get_ticklabels():
#    # label is a Text instance
#    print label
#    label.set_color('red')
#    label.set_rotation(45)
#    label.set_fontsize(0)
#for label in ax2.yaxis.get_ticklabels():
#    # label is a Text instance
#    print label
#    label.set_color('red')
#    label.set_rotation(45)
#    label.set_fontsize(0)

#for line in ax1.yaxis.get_ticklines():
#    # line is a Line2D instance
#    line.set_color('red')
#    line.set_markersize(15)
#    line.set_markeredgewidth(0)

show()
F.savefig(outfilename, dpi=300)



#rect = F.figurePatch # a rectangle instance
#rect.set_facecolor('goldenrodyellow')
#ax1 = F.add_axes([0.1, 0.7, 0.9, 0.9])
#rect = ax1.axesPatch
#rect.set_facecolor(0.75,cmap=my_cmap)
#for label in ax1.xaxis.get_ticklabels():
#    # label is a Text instance
#    label.set_color('red')
#    label.set_rotation(45)
#    label.set_fontsize(16)
#for line in ax1.yaxis.get_ticklines():
#    # line is a Line2D instance
#    line.set_color('green')
#    line.set_markersize(25)
#    line.set_markeredgewidth(3)