from numpy import *
import numpy as np
from matplotlib.pyplot import *
import matplotlib as mpl
mpl.rcParams['xtick.major.size'] = 8
mpl.rcParams['xtick.minor.size'] = 4
mpl.rcParams['xtick.major.width'] = 1.5
mpl.rcParams['xtick.minor.width'] = 1.5
mpl.rcParams['ytick.major.size'] = 8
mpl.rcParams['ytick.minor.size'] = 4
mpl.rcParams['ytick.major.width'] = 1.5
mpl.rcParams['ytick.minor.width'] = 1.5

ticksize=20
labelsize=22

data=loadtxt('DOY 120-126, 1998 STOF effective data.dat')
m_q=data[:,0]
mass=data[:,1]

H, xedges, yedges = np.histogram2d(m_q,mass,bins=np.logspace(-1,2,300))
H = np.rot90(H)
H = np.flipud(H)
Hmasked = np.ma.masked_where(H==0,H)


figure(figsize=(10,8))
pcolormesh(xedges,yedges,Hmasked)
#colorbar()
#H = np.rot90(H)
#Hmasked = np.ma.masked_where(H==0,H)
#pcolormesh(xedges,yedges,Hmasked,cmap='gnuplot')

ylim(0.1,100)
xlim(0.1,100)
yscale('log')
xscale('log')



xticks([1,10,100],fontsize=ticksize)
yticks([0.1,1,10,100],fontsize=ticksize)
#text(25,1e-4,'STOF Flux',fontsize=labelsize,color='b')
#text(25,13e-6,'One Count Level\n      of STOF',fontsize=labelsize,color='g')
#title('1999-139 02:11:02~139 07:12:00',fontsize=labelsize)
xlabel('Mass/Charge [amu/e]',fontsize=labelsize)
ylabel('Mass [amu]',fontsize=labelsize)
#text(13,0.05,'~4 to 10AU',fontsize=labelsize)
#text(300,0.05,'CIR-01',fontsize=labelsize)
#text(13,0.2,'The Connection Distance',fontsize=labelsize)
tick_params(right='off',top='off',which='both')
annotate("H$^+$", xy=(1.4,0.7), xytext=(10, 0.3), fontsize=22,
    arrowprops=dict(arrowstyle="->", lw=2),)

annotate("He$^{++}$", xy=(2.3,2.7), xytext=(10, 0.65), fontsize=22,
    arrowprops=dict(arrowstyle="->", lw=2),)

annotate("He$^{+}$", xy=(4.8,3.5), xytext=(10, 1.5), fontsize=22,
    arrowprops=dict(arrowstyle="->", lw=2),)


annotate("heavy ions", xy=(7,51), xytext=(15, 6), fontsize=22,
    arrowprops=dict(arrowstyle="->", lw=2),)
annotate("", xy=(3.5,13.5), xytext=(15, 6), fontsize=22,
    arrowprops=dict(arrowstyle="->", lw=2),)
#savefig('one_example.png')
cbar = colorbar()
cbar.ax.tick_params(labelsize=20) 
cbar.ax.set_ylabel('Counts',fontsize=labelsize)

show()

