import numpy as np
from matplotlib.ticker import NullFormatter
import matplotlib as mpl
import matplotlib.pyplot as plt

# ----------
# Formatting
# ----------
mpl.rcParams.update({
    'mathtext.fontset'            : 'cm',
    'axes.unicode_minus'          : False,
    'axes.formatter.use_mathtext' : True,
})

plt.rcParams.update({
    'font.size': 14,
    'figure.figsize'    : [8.0, 5.0],
    'font.family'       : "serif",
    'font.serif'        : "cmr10",
    'xtick.major.size'  : 6,
    'xtick.minor.size'  : 3,
    'ytick.major.size'  : 6,
    'ytick.minor.size'  : 3,
})

LabelSize=14
MarkerSize=75
MarkerSize=95
TickSize=20
LegendSize=14
nullfmt=NullFormatter() # no labels

SMALL_SIZE_2 = 19
SMALL_SIZE = 20
MEDIUM_SIZE = 24
BIGGER_SIZE = 24
BIGGEST_SIZE = 30

plt.rc('font', size=SMALL_SIZE)          # controls default text sizes
plt.rc('axes', titlesize=SMALL_SIZE)     # fontsize of the axes title
plt.rc('axes', labelsize=MEDIUM_SIZE)    # fontsize of the x and y labels
plt.rc('xtick', labelsize=SMALL_SIZE)    # fontsize of the tick labels
plt.rc('ytick', labelsize=SMALL_SIZE)    # fontsize of the tick labels
plt.rc('legend', fontsize=SMALL_SIZE_2)    # legend fontsize
plt.rc('figure', titlesize=BIGGER_SIZE)  # fontsize of the figure title

# ---------
# Import data
# ---------
pminmaxgapNLO = np.loadtxt('p_NLOgap_D0p140.dat')
pminmaxgapLO = np.loadtxt('p_LOgap_D0p140.dat')
pminmax = np.loadtxt('p_NLOgap_D0p0.dat')

# ----------
# Plot
# ----------
plt.axvline(2.6, c='black', ls=':', alpha=1)
plt.plot(pminmaxgapNLO.transpose()[0],pminmaxgapNLO.transpose()[1], color = 'C2')
plt.plot(pminmaxgapNLO.transpose()[0],pminmaxgapNLO.transpose()[2], color = 'C2')
plt.fill_between(pminmaxgapNLO.transpose()[0], pminmaxgapNLO.transpose()[1], pminmaxgapNLO.transpose()[2], 
                 color='C2', alpha=0.4, label=r'$\Delta^{\!*}_{\rm CFL} = 140 \, {\rm MeV}$ (NLO)')

plt.plot(pminmaxgapLO.transpose()[0],pminmaxgapLO.transpose()[1], color = 'tab:blue')
plt.plot(pminmaxgapLO.transpose()[0],pminmaxgapLO.transpose()[2], color = 'tab:blue')
plt.fill_between(pminmaxgapLO.transpose()[0], pminmaxgapLO.transpose()[1], pminmaxgapLO.transpose()[2], 
                 color='tab:blue', alpha=0.4, label=r'$\Delta^{\!*}_{\rm CFL} = 140 \, {\rm MeV}$ (LO)')


plt.plot(pminmax.transpose()[0],pminmax.transpose()[1], color = 'black',alpha=0.2)
plt.plot(pminmax.transpose()[0],pminmax.transpose()[2], color = 'black',alpha=0.2)
plt.fill_between(pminmax.transpose()[0], pminmax.transpose()[1], pminmax.transpose()[2], alpha=0.2, color = "black", label=r'NQM', hatch="X")
plt.xticks(np.arange(2, 6.5, 1))
plt.xlim(1.835,5.2)
plt.axhline(1, c='black', ls='--', alpha=0.5, dashes=(5, 3))
plt.yticks(np.arange(0, 1.6, 0.5))
plt.xticks([2,2.6,3,4,5])
plt.ylim(0,1.55)
plt.xlabel(r'$\mu_{\rm B}$ [GeV]')
plt.ylabel(r'$p/p_{\rm free}$')
plt.legend(loc='lower right')
plt.savefig('pressure.pdf', format='pdf', bbox_inches='tight')
plt.close()