import numpy
import matplotlib
import matplotlib.pyplot as plt
from numpy import arange

# LaTeX like fonts in the figure
#plt.rc('text', usetex=True)
plt.rc('font', family='serif')
#plt.rc('font', serif='Palatino')
#plt.rc('font', cursive='Zapf Chancery')
#plt.rc('font', monospace='Courier')

matplotlib.rcParams['xtick.labelsize'] = 14 
matplotlib.rcParams['ytick.labelsize'] = 14

from matplotlib.ticker import AutoMinorLocator
XminorLocator = AutoMinorLocator()
YminorLocator = AutoMinorLocator(2)


infile = open('CloudMHI.txt','r')

length = []

for line in infile:
	sl = line.split()[0]	
	length.append(float(sl))
	
print length

binwidth = 1.0

plt.hist(length, bins=arange(-binwidth/2.0, max(length) + binwidth, binwidth), color='red', histtype='stepfilled')


# Set font
csfont = {'fontname':'Liberation Serif','fontsize':17}
plt.xlabel('Length / kpc', **csfont)
plt.ylabel('Count', **csfont)

# We have manually specified the x-range

axes = plt.gca()
axes.set_xlim([4.0,11.0])
axes.xaxis.set_minor_locator(XminorLocator)
axes.yaxis.set_minor_locator(YminorLocator)


xlim = plt.xlim()[1] - plt.xlim()[0]
ylim = plt.ylim()[1] - plt.ylim()[0]

plt.xlabel("log(Cloud HI Mass / M$_{\odot}$)")
plt.ylabel("Count")

plt.gca().set_aspect(xlim/ylim,adjustable='box')
	
plt.savefig('CloudMHI.png',dpi=100,facecolor='white',bbox_inches='tight')

#plt.show()
