In [40]:
%clear
%pylab inline
from matplotlib.ticker import ScalarFormatter, FormatStrFormatter, LogLocator, NullFormatter, MultipleLocator, MaxNLocator
from os import path
import re
Populating the interactive namespace from numpy and matplotlib

Helper functions

In [41]:
reFloat = r'([+-]?\d+(?:\.\d+)?(?:[eE][+-]\d+)?)'
fit_pattern = re.compile(r'# (\w+)\s+: %s' % reFloat)
def load_fit_data(fname):
    res = {}
    for line in open(fname):
        match = fit_pattern.search(line)
        if match:
            name = match.group(1)
            val  = float(match.group(2))
            res[name] = val
    return res
class transform:
    class ident:
        def __call__(self, x): return x
    class scale:
        def __init__(self, a): self.a = float(a)
        def __call__(self, x): return self.a*x
    class shif_scale:
        def __init__(self, b, a): self.a = float(a); self.b = float(b); 
        def __call__(self, x): return self.a*(x-self.b)
markers = ['o', 's', '>', 'v', '^', 'd', '<']
im = 0
def get_marker():
    global im
    mm = markers[im]
    im = (im+1) % len(markers)
    return mm

Common settings

In [42]:
extrap_pars = 'deg2_num6' # 'deg2_numAll', 'deg1_num4'
invm_scale = 1000.
data_path = path.expanduser('~/PhD/projects/HubbardLadder/pyfigures/data_new')

Main plot functions

In [43]:
def load_and_plot(ax, L, t_perp, filling, bname, all_x, varname, xtransform, ytransform, fit_color, marker_color):
    markers = ['o', '>', 's']
    for i,site_x in enumerate(all_x):
        # load fit
        fname =  data_path + '/{bname}_fit_{pars}_L={L}_n={fill}_tperp={tperp}_x={x}.txt'.format(bname=bname, pars=extrap_pars, L=L, x=site_x, fill=filling, tperp=t_perp)
        if not path.exists(fname):
            print '# data n={} t_perp={} not found.'.format(filling, t_perp), fname
            return
        d = np.loadtxt(fname)
        fit_res = load_fit_data(fname)
    
        sel = np.ones(len(d), dtype=bool)
        if 'fit_cut' in fit_res:
            fit_cut = float(fit_res['fit_cut'])
            sel = d[:,0] <= fit_cut
        ax.plot(xtransform(d[sel,0]), ytransform(d[sel,1]), '-', c=fit_color)
        ax.plot(xtransform(d[-sel,0]), ytransform(d[-sel,1]), '--', c=fit_color)
    
        # load data
        fname =  data_path + '/{bname}_L={L}_n={fill}_tperp={tperp}_x={x}.txt'.format(bname=bname, L=L, x=site_x, fill=filling, tperp=t_perp)
        if not path.exists(fname):
            print '# data n={} t_perp={} not found.'.format(filling, t_perp), fname
            return
        d = np.loadtxt(fname)

        ax.plot(xtransform(d[:,0]), ytransform(d[:,2]), markers[i], color=marker_color, mec=marker_color, mfc='w', label='$%s=%.0f$'% (varname, site_x))

def make_plot(L, t_perp, filling, what, all_x, varname):
    figure(figsize=(10,6))
    subplots_adjust(left=0.25, right=0.95, top=0.95, hspace=0.1, wspace=0.05)

    ax1 = subplot(121)
    load_and_plot(ax1, L, t_perp, filling, what+'_extrap_bonddim', all_x, varname, transform.scale(invm_scale), transform.ident(),
                  fit_color='g', marker_color='r')
    legend(loc='best')
    ax1.set_xlabel('1000/M')
    xlim = ax1.get_xlim()
    ax1.set_xlim(xmin=xlim[1], xmax=0.)
    
    ax2 = subplot(122)
    load_and_plot(ax2, L, t_perp, filling, what+'_extrap_variance', all_x, varname, transform.ident(), transform.ident(),
                  fit_color='b', marker_color='y')
    ax2.set_xlim(xmin=0)
    ax2.set_xlabel('Var[H]')
    
    ax3 = twiny(ax2)
    load_and_plot(ax3, L, t_perp, filling, what+'_extrap_truncation', all_x, varname, transform.ident(), transform.ident(),
                  fit_color='k', marker_color='c')
    ax3.set_xlim(xmin=0)
    ax3.set_xlabel('Truncated Weight')
    
    ax2.yaxis.set_major_formatter(NullFormatter())
    
In [44]:
L = 128
t_perp = 1.0
filling = 0.875

make_plot(L=L, t_perp=t_perp, filling=filling, what='dens', all_x=[64,40,16], varname='i')
suptitle('Density');

make_plot(L=L, t_perp=t_perp, filling=filling, what='dens_dens_avg', all_x=[21,34,66], varname='r')
suptitle('Dens-Dens');

make_plot(L=L, t_perp=t_perp, filling=filling, what='pairfield_avg', all_x=[25,30,40], varname='r')
suptitle('Pairfield');
In [ ]: