b_ee[c] = -np.log(b_es[c])
b_ee_diff = OrderedDict()
for c in b_ee:
    b_ee_diff[c] = np.array(b_ee[c][:8])-np.array(b_ee[0][:8])
b_ee_points = [[b_ee_diff[c][j] for c in b_ee_diff] if x else b_ee_diff.keys() for j in reversed(range(8)) for x in range(2)]
bb_ee = OrderedDict()
for c in bb_es:
    bb_ee[c] = -np.log(bb_es[c])
bb_ee_diff = OrderedDict()
for c in bb_es:
    bb_ee_diff[c] = np.array(bb_ee[c][:8])-np.array(bb_ee[0][:8])
bb_ee_points = [[bb_ee_diff[c][j] for c in bb_ee_diff] if x else bb_ee_diff.keys() for j in reversed(range(8)) for x in range(2)]

#print b_ee_points
from SimplePEPS.tools.plot import subplots
(fig, axs), bigax = subplots(1, 2, sharey='all')
plt.sca(axs[0])

from SimplePEPS.ed import perturb as edp
c_func = lambda x, y, j, num, t: ['k', 'k', 'b', 'b', 'r', 'r', 'g', 'g'][t] if t<8 else 'y'
fig, ax = edp._spec_plot(b_es, yfunc = lambda e:-np.log(e), cfunc=c_func,
              xlabel='Perturbation h', ylabel='Entanglement energy',# title='Quasi-1D HFBI Perturbed Entanglement Spectrum',
              ylim=[-1, 30])

formatter = mtick.FuncFormatter(lambda x, y: (sci_notation(b_es.keys()[int(y)]) if y is not None else ''))
ax.xaxis.set_major_formatter(formatter)
ax_inset=fig.add_axes([0.22,0.45,0.2,0.3])
ax_inset.plot(*b_ee_points, marker='.', ls='-')
#print b_ee_points[0], b_ee_points[1]
plt.yscale('symlog', linthreshy=1e-4)
plt.xscale('symlog', linthreshx=1e-5)
scb_ans = corrbound_data(scb, range(1,maxL+1))


IO.go_to_data_parent('hardcoreboson', parent='Data//FBI-TM')
IO.add_to_path()
hcb = IO.get_state()
maxL = 10
hcb_ans = corrbound_data(hcb, range(1, maxL+1))


data = [(L,)+scb_ans.get(L, (None, None, None, None))+hcb_ans.get(L,(None, None, None, None)) for L in scb_ans]
from tabulate import tabulate
#print tabulate(data, ['L', 'SCB O', '', 'SCB S', '', 'HCB O', '', 'HCB S', ''])

from SimplePEPS.tools.plot import subplots
(fig, axs), bigax = subplots(2, 2, sharex='all', sharey='row')

plt.sca(axs[0][0])
plt.plot([d[0] for d in data], [d[1] for d in data], color='b', ls='', marker='.')
plt.sca(axs[1][0])
plt.plot([d[0] for d in data], [d[3] for d in data], color='k', ls='', marker='.')
plt.sca(axs[0][1])
plt.plot([d[0] for d in data], [d[5] for d in data], color='b', ls='', marker='.')
plt.sca(axs[1][1])
plt.plot([d[0] for d in data], [d[7] for d in data], color='k', ls='', marker='.')

import PEPS.analysis as a
fit_func = a.expic
#fit_func2 = lambda x, b, c: b*x**c
#fit_func3 = lambda x, b, c: np.log(b*x**c)
extrapolate_pnts = np.arange(0, 11, 0.05)