# -*- coding: utf-8 -*-
from __future__ import division
import numpy as np
from numpy import pi
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import matplotlib
import os,sys
from matplotlib import rc
plt.rc('text', usetex=True)
plt.rc('font', family='serif',serif='Times',size=54)
I=0
folder='widthsout'
fsize=(20,14)
fig=plt.figure(figsize=fsize)
axin1=np.array([1,2,3,2,5,3,4,4,3])
axin2=np.array([1,1,1,2,1,2,3,2,3])
letters=['a','b','c','d','e','f','g','h','i']
colours=['cyan','red','black','forestgreen','blue','chartreuse','magenta','teal']
fontsizela=64
indsarray=np.array([[0,1,2],[3,4,5],[6,7,8]])
Grid=gridspec.GridSpec(3,3)
fs=np.loadtxt(folder+'/fs.txt')
T=np.loadtxt(folder+'/params.txt')
gs=np.loadtxt(folder+'/gs.txt')
es=np.loadtxt(folder+'/es.txt')
ss=np.loadtxt(folder+'/ss.txt')
vs=np.loadtxt(folder+'/vs.txt').reshape((len(gs),len(ss),len(fs),len(es)))
es=es[::4]
vs=vs[:,:,:,::4]
markers=['P','v','s','x','D','1','.','p','*']
for i in range(len(gs)):
    for j in range(len(fs)):
        exec("ax%d%d=fig.add_subplot(Grid[%d,%d])"%(i+1,j+1,i,j))
        if i==2:
            exec("ax%d%d.set_xlabel('$\\epsilon$',fontsize=fontsizela)"%(i+1,j+1))
        else:
            exec("ax%d%d.set_xticklabels([])"%(i+1,j+1))
        if j==0:
            exec("ax%d%d.set_ylabel('$v$',rotation=0,fontsize=fontsizela)"%(i+1,j+1))
            exec('ax%d%d.yaxis.set_label_coords(-0.2,0.35)'%(i+1,j+1))
        else:
            exec("ax%d%d.set_yticklabels([])"%(i+1,j+1))
        m=-1
        for a in np.array([0,2,3,5]):
            m=m+1
            exec("l%d%d=ax%d%d.scatter(es,vs[i,a,j,:],color=colours[m],s=300,marker=markers[m],zorder=10-a)"%(i+1,j+1,i+1,j+1))
        
        exec("ax%d%d.set_ylim(0.06,0.24)"%(i+1,j+1))
labels,ls=[],[]
for a in np.array([0,2,3,5]):
    exec("ls.append(l%d%d)"%(i+1,j+1))
    labels.append('$\mathrm{\sigma=}$%3.2f'%ss[a])
    ncol=len(ss)
fig.legend(labels,loc='upper center',ncol=4,fontsize=38,frameon=False,markerscale=4)
positions=[0.0885,0.88,0.3625,0.88,0.6375,0.88,0.0885,0.6075,0.3625,0.6075,0.6375,0.6075,0.0885,0.328,0.3625,0.328,0.6375,0.328]
for i in range(9):
    position_x,position_y=positions[2*i:2*i+2]
    position_x+=0.05
    position_y-=0.05
    fig.text(position_x,position_y, '(%s)'%letters[i], fontsize=54)

plt.savefig('fig9.eps',pad_inches=0)
