import gzip
import os
import sys
from collections import Counter
from Ordinal.utils import jaggedness
import pickle
import numpy as np

telescope = np.genfromtxt('fact_expectation.txt')
nclasses_telescope = len(telescope)

jag = jaggedness(telescope)
print(jag)

import matplotlib.pyplot as plt
from matplotlib.pyplot import figure
import seaborn as sns

sns.set_theme('paper')
sns.set_style('dark')
sns.set(font_scale=0.7)

# figure, axis = plt.subplots(1, 2, figsize=(8, 7))
ymax = 0.4

figure(figsize=(8, 4), dpi=300)

ax=plt.subplot(1, 1, 1)
classes = np.arange(1, nclasses_telescope+1)
plt.bar(classes, telescope, width=1)
# ax.bar_label(telescope)
ax.set_ylim(0, ymax)
ax.set_xlabel("energy bin")
ax.set_xticks(classes)
ax.set_title(f'FACT data ({jag:.4f})')
for index, data in enumerate(telescope):
    plt.text(x=index+0.56 , y=data+0.005 , s=f"{data:.4f}")


plt.subplots_adjust(wspace=0.1, hspace=0)
plt.savefig('telescope_prevalence.pdf', bbox_inches='tight')