Esempio n. 1
0
File: plot.py Progetto: gauden/hfadb
 def render(self):
     # Set global font to ensure ability to display Cyrillic
     plt.rc('font', **{'sans-serif': ['Helvetica', 'Arial'],
                       'family': 'sans-serif'})
     for lang in self.langs:
         figure, ax_array = self.figures[lang]
         figure, title = self._set_up_figure(figure, lang)
         self._get_axis_limits()
         self._render_axes(ax_array, lang)
         self._save_fig(figure, title, lang)
Esempio n. 2
0
            for m, phi in enumerate(phis):
                print n,m,alphas.size
                lamb = phi*np.sqrt(2*np.pi*alpha)
                eps[n,m] = get_eq_eps( gamma, eta, alpha, lamb )
                stoc_eps[n,m] =  np.mean(full_stoc_sigma(0.01, dt, N, -gamma,
                                               eta, alpha, lamb, 200,
                                               discard=discard))

        with open("figure_5_3.pik","w") as fi:
            print "Writing pickle to figure_5_3.pik"
            pic.dump({'alphas':alphas,'phis':phis,'mean_field':eps,'stochastic':stoc_eps},fi)

    print "Plotting..."
    
    font = {'size':12}
    plt.rc('font',**font)

    fig, (ax1,ax2) = ppl.subplots(1,2,figsize = (12,5))
    
    alphas2,phis2 = np.meshgrid(np.arange(alphas.min(),alphas.max()+dalpha,dalpha)-dalpha/2,
                                np.arange(phis.min(),phis.max()+dphi,dphi)-dphi/2)

    yellorred = brewer2mpl.get_map('YlOrRd','Sequential',9).mpl_colormap

    p = ax1.pcolormesh(alphas2,phis2,eps.T,cmap=yellorred, rasterized=True)
    ax1.axis([alphas2.min(),alphas2.max(),phis2.min(),phis2.max()])

    #xticks = np.arange(alphas.min(),alphas.max(),0.5)
    #xlabels = np.arange(alphas.min(),alphas.max(),0.5)-alphas.min()

    #yticks = np.arange(phis.min(),phis.max(),0.5)
Esempio n. 3
0
tau = 0.2
#phi = 1.0
thetas = np.arange(-4.0,4.0,0.4)
deltas = np.arange(0.0,2.1,0.5)
phis = np.arange(0.0,100.0,0.1)
alpha = 0.5
#alphas = np.arange(0.001,4.0,0.05)
ndeltas = len(deltas)
nphis = len(phis)
#nalphas = len(alphas)
epss = np.zeros((ndeltas,nphis))
ls = np.zeros((ndeltas,nphis))

if __name__=='__main__':
    
    plt.rc('text',usetex=True)
    plt.rc('font',**{'family':'sans-serif','sans-serif':['Helvetica']})
    try:
        print 'data loaded'
        data = np.load(open('../data/mean_field_ratedist.npz','rb'))
        epss = data['eps']
        phis = data['phis']
        deltas = data['deltas']
        tau = data['tau']
        ls = data['ls']
           
    except:

        print 'no data, running again'
        for nd,delta in enumerate(deltas):
            y = eta**2/(2*gamma)
## DO principales + vitalicios
## numero de socios por categoria
numero_socios = [str(len(principales) + len(vitalicios)),
                 str(250-len(principales)-len(vitalicios))]

print "Socios privilegiados con el voto " + str(len(principales) +
        len(vitalicios) + len(activos))

y = [princi_money + vitali_money, activo_money + otros_money]
annotate = [locale.format("%d", y[0], grouping=True) + " S/.",
            locale.format("%d", y[1], grouping=True) + " S/."]

width = 0.35
bar_color = ["r", "#66c2a5"]
plt.rc('font', **{'family': 'DejaVu Sans'})
fig, ax = plt.subplots(1, figsize=(8,6))
ind = np.arange(2)
xdata = ind + 0.05 + width
ax.bar(ind, y)
ax.set_xticks(ind + 0.4)
ax.set_xticklabels(["principales y vitalicios\n(" + numero_socios[0] + " socios)", 
                    "otros socios\n(" + numero_socios[1] + " socios)", 
                    ],
                    rotation="horizontal", multialignment="center")
ax.autoscale()
ax.set_title(u'Ganancias de socios principales y vitalicios\n comparados con el resto de socios',
        fontdict = {'fontsize':22}
        )

y_labels = ["0", "1,000,000", "2,000,000", "3,000,000", "4,000,000",
Esempio n. 5
0
    return out


observation = pm.Poisson("obs", lambda_, value=datos, observed=True)
model = pm.Model([observation, lambda_1, lambda_2, tau])
mcmc = pm.MCMC(model)
mcmc.sample(50000, 10000, 1)

lambda_1_samples = mcmc.trace('lambda_1')[:]
lambda_2_samples = mcmc.trace('lambda_2')[:]

tau_samples = mcmc.trace('tau')[:]

fig, (ax1, ax2, ax3) = plt.subplots(nrows=3, ncols=1)

plt.rc('font', **{'family': 'DejaVu Sans'})
plt.subplot(311)
plt.title(u'''Distribución posterior de las variables
            $\lambda_1,\;\lambda_2,\;tau$''')
plt.hist(lambda_1_samples,
         histtype="stepfilled",
         bins=30,
         alpha=0.85,
         normed=True)
plt.xlim([150000, 250000])
plt.xlabel("valor de $\lambda_1$")

plt.subplot(312)
#ax.set_autoscaley_on(False)
plt.hist(lambda_2_samples,
         histtype="stepfilled",
Esempio n. 6
0
##import matplotlib
##matplotlib.use('Agg')
##import matplotlib.pyplot as plt
import prettyplotlib as ppl
from prettyplotlib import plt
import numpy as np
import cPickle as pic
import sys
plt.rc('text',usetex=True)

try:
    sys.argv[1]
    data = pic.load(open(sys.argv[1],"rb"))
    #data = np.load(open(sys.argv[1]))
except:
    fi = open("../data/pickle_alpha_1","rb")
    data = np.load(fi)

taus = data[3]
alphas = data[2]
eps = data[0]
delta = 0.1

string = [r'$\tau\delta$ = %.2f' % float(delta*t) for t in taus]
#string2 = [r'$\tau$ = '+str(data[3][i]) for i in range(5)]
maxmmse = np.max(eps)
#maxf = np.max(data[1])
def f(x):
    ppl.plot(alphas,eps[:,x]/maxmmse,label=string[x],ax=ax1)
#	ax2.plot(data[2],data[1][:,x]/maxf,label=string2[x])
#plt.close()
Esempio n. 7
0
def main():
    description = """Simple bar plot of table. Input is a table from a file or
    standard input."""

    parser = argparse.ArgumentParser(
        description=description,
        formatter_class=RawTextHelpFormatter
    )
    parser.add_argument(
        '-f',
        '--filename',
        action='store',
        metavar='table.csv',
        help='''A table of the format:
                x_title,  y_title,  Main_title
                x_label1, value1
                x_label2, value2''',
        required=False,
        dest='filename',
    )

    args = parser.parse_args()

    if args.filename:
        filename = args.filename.strip()
    else:
        parser.print_help()
        sys.exit(1)

    y = []
    x = []
    for line in open(filename, "r").readlines():
        line = line.strip()

        res = re.search("[0-9]+", line)
        if not res:
            line = line.split(",")
            x_lab = line[0]
            y_lab = line[1]
            main = line[2]
        else:
            line = line.split(",")
            if len(line) < 2:
                y.append(float(line[0]))
            else:
                x.append(line[0])
                y.append(float(line[1]))
            print(line)

    if len(x) < 1:
        x = range(1, len(y) + 1)

    plt.rc('font', **{'family': 'DejaVu Sans'})
    fig, ax = plt.subplots(1, figsize=(8, 6))

    width = 0.2
    ind = np.arange(len(y))
    xdata = ind + 0.05 + width
    ax.bar(ind, y)
    ax.set_xticks(ind + 0.5)
    ax.set_xticklabels(x)
    ax.autoscale()
    ax.set_title(
        main,
        fontdict={'fontsize': 20},
    )

    plt.ylabel(y_lab, fontdict={'fontsize': 15})
    plt.xlabel(x_lab, fontdict={'fontsize': 15})
    plt.tick_params(axis="y", which="major", labelsize=10)
    plt.tick_params(axis="x", which="major", labelsize=10)

    ppl.bar(ax, np.arange(len(y)), y, grid="y")

    plt.tight_layout()
    print("The plot has been saved as ``out.png``")
    fig.savefig("out.png")