Ejemplo n.º 1
0
 def plot_sta(self, ax, vname, station, date, label):
     print vname, station, date, label
     if label == 'Free':
         nc = self.free
         if self.t_free is None:
             ocean_time = nc.variables['ocean_time'][:]
             time = netCDF4.date2num(date, self.sta_JST)
             if type(time) == np.int64:
                 t = np.where(ocean_time == time)[0][0]
             else:
                 t0 = np.where(ocean_time == time[0])[0][0]
                 t1 = np.where(ocean_time == time[1])[0][0]
                 t = np.arange(t0, t1)
             self.t_free = t
         else:
             t = self.t_free
     elif label == 'Assi':
         nc = self.assi
         if self.t_assi is None:
             ocean_time = nc.variables['ocean_time'][:]
             time = netCDF4.date2num(date, self.sta_JST)
             t = np.where(ocean_time == time)[0][0]
             self.t_assi = t
         else:
             t = self.t_assi
     if vname == 'DIN':
         NH4 = nc.variables['NH4'][t,station-1,:]
         NO3 = nc.variables['NO3'][t,station-1,:]
         var = NH4 + NO3
     elif vname == 'PON':
         LDeN = nc.variables['LdetritusN'][t,station-1,:]
         SDeN = nc.variables['SdetritusN'][t,station-1,:]
         var = LDeN + SDeN
     elif vname == 'POP':
         LDeP = nc.variables['LdetritusP'][t,station-1,:]
         SDeP = nc.variables['SdetritusP'][t,station-1,:]
         var = LDeP + SDeP
     else:
         var = nc.variables[vname][t,station-1,:]
     line = {'Free': '--', 'Assi': '-'}
     if type(t) == np.int64:
         depth = self.calculate_depth(nc, t, station)
         ax.plot(var, depth, line[label], label=label)
     else:
         depth  = self.calculate_depth(nc, t[0], station)
         #ax.errorbar(np.mean(var, axis=0), depth, xerr=np.std(var, axis=0), fmt=line[label], label=label)
         mean = np.mean(var, axis=0)
         std = np.std(var, axis=0)
         #ax.fill_betweenx(depth, mean-std, mean+std, label=label)
         #ax.plot(mean, depth, line[label])
         special.errorfill(mean, depth, xerr=std, label=label, ax=ax, alpha_fill=0.1)
            stim_perm = stim[perm]
            pred_perm = clf.fit(stim_perm, voxels).predict(stim_perm)
            # compute the test statistic
            T_perm.append(linalg.norm(pred_perm - voxels, 'fro'))

    pvals_ls.append(perm_p_values(T_a_i, np.array(T_perm)))

# plot the resulting p-value distributions
from mpltools import special
pvals_rsa = np.array(pvals_rsa)
pvals_ls = np.array(pvals_ls)
power_rsa = 1. * (pvals_rsa < .05)
power_ls = 1. * (pvals_ls < .05)

plt.figure(figsize=(4, 4))
special.errorfill(a_space, np.mean(power_rsa, axis=1),
                  np.std(power_rsa, axis=1), label='RSA')
special.errorfill(a_space, np.mean(power_ls, axis=1),
                  np.std(power_ls, axis=1), label='LS')

plt.xlim((0, np.max(a_space)))
plt.ylim((0, 1.01))
plt.legend(loc=4)
plt.plot(a_space, power_rsa.mean(1), color='b', linewidth=2)
plt.plot(a_space, power_ls.mean(1), color='g', linewidth=2)
plt.ylabel('Power')
plt.xlabel('Effect size')
plt.subplots_adjust(bottom=.15, left=.15)
plt.savefig('power_%s.png' % random_effects)
plt.show()
Ejemplo n.º 3
0
def wplot(typ,*args,**kwargs):
    save=kwargs.pop('save',0)
    hold=kwargs.pop('hold',False)
    title=kwargs.pop('title',False)
    legs=kwargs.pop('legends',False)
    invert=kwargs.pop('invert',0)
    if not legs:
        legs=kwargs.pop('legend',False)
    if not legs:
        legs=kwargs.pop('leg',False)
    lkw=kwargs.pop('legopt',{})
    if 'xlabel' in kwargs:
        plt.xlabel(kwargs.pop('xlabel'))
    if 'ylabel' in kwargs:
        plt.ylabel(kwargs.pop('ylabel'))
    if 'labels' in kwargs:
        labs=kwargs.pop('xlabel')
        plt.xlabel(labs[0])
        plt.ylabel(labs[1])
    if 'log' in kwargs:
        lg=kwargs.pop('log')
        if not isinstance(lg,str):
            if typ!= 'hist':
                kwargs['log']='xy'
            else:
                kwargs['log']=lg
        else:
            if 'x' in lg:
                plt.xscale('log')
            if typ!= 'hist':
                if 'y' in lg :
                    plt.yscale('log')
            else:
                if 'y' in lg:
                    kwargs['log']=1
                if 'x' in lg:
                    if min(args[0])<=0:
                        args=([ar for ar in args[0] if ar>0],)+args[1:]
                    if not 'bins' in kwargs or isinstance(kwargs['bins'],int):
                        kwargs['bins']=np.logspace(log10(min(args[0])),
                            log10(max(args[0])),kwargs.get('bins',100),10)
    elif typ=='hist' and min(args[0])>0 and max(args[0])/min(args[0])>10**3:
        kwargs['log']=1
    if 'xs' in kwargs :
        xs=kwargs.pop('xs')
        args=list(itertools.chain.from_iterable([[xs[:len(a)],a] for a in args]))
    if not args:
        return
    try:
        if typ=='plot':
            handle=plt.plot(*args,**kwargs)
        if typ =='hist':
            if not 'bins' in kwargs:
                kwargs['bins']=100
            if kwargs.pop('cleverbins',False):
                if isinstance(kwargs['bins'],int):
                    kwargs['bins']=min(kwargs['bins'],len(args[0])/20)
            kwargs['hold']=1
            handle=[plt.hist(a,**kwargs)[2][0] for a in args]
        if typ=='scatter':
            handle=plt.scatter(*args,**kwargs)
        if typ=='error':
            handle=plt.errorbar(*args,**kwargs)
        if typ=='errorfill':
            handle=pltspecial.errorfill(*args,**kwargs)
        if typ=='contour':
            handle=plt.contour(*args,**kwargs)
        if typ=='contourf':
            handle=plt.contourf(*args,**kwargs)
        if typ=='bar':
            handle=plt.bar(*args,**kwargs)
    except e:
        print "Cannot plot:", sys.exc_info()[0],e
        return
    if title:
        plt.title(title)
    if legs:
        plt.legend(handle,legs,**lkw)
    if invert:
        if 'x' in invert:
            plt.xlim(plt.xlim()[::-1])
        elif 'y' in invert:
            plt.ylim(plt.ylim()[::-1])
    if save:
        plt.savefig(save)
        plt.clf()
        plt.close()
    elif not hold:
        plt.show()
        return handle
Ejemplo n.º 4
0
"""
================
Plot `errorfill`
================

When you have continuous data measurement and errors associated with every data point, plotting error bars can get really noisy. `special.errorfill` plots a filled region to represent the error values instead of using individual bars.
"""

import numpy as np
import matplotlib.pyplot as plt

from mpltools import special

x = np.linspace(0, 2 * np.pi)
y_sin = np.sin(x)
y_cos = np.cos(x)

y_err = 0.2
special.errorfill(x, y_sin, y_err)
special.errorfill(x, y_cos, y_err, alpha_fill=0.1)

plt.show()

Ejemplo n.º 5
0
"""
================
Plot `errorfill`
================

When you have continuous data measurement and errors associated with every data point, plotting error bars can get really noisy. `special.errorfill` plots a filled region to represent the error values instead of using individual bars.
"""

import numpy as np
import matplotlib.pyplot as plt

from mpltools import special

x = np.linspace(0, 2 * np.pi)
y_sin = np.sin(x)
y_cos = np.cos(x)

y_err = 0.2
special.errorfill(x, y_sin, y_err, label='sin', label_fill='sin error')
special.errorfill(x, y_cos, y_err, label='cos', label_fill='cos error',
                  alpha_fill=0.1)
plt.legend()

plt.show()

Ejemplo n.º 6
0
"""
================
Plot `errorfill`
================

When you have continuous data measurement and errors associated with every data point, plotting error bars can get really noisy. `special.errorfill` plots a filled region to represent the error values instead of using individual bars.
"""

import numpy as np
import matplotlib.pyplot as plt

from mpltools import special

x = np.linspace(0, 2 * np.pi)
y_sin = np.sin(x)
y_cos = np.cos(x)

y_err = 0.2
special.errorfill(x, y_sin, y_err, label="sin", label_fill="sin error")
special.errorfill(x, y_cos, y_err, label="cos", label_fill="cos error", alpha_fill=0.1)
plt.legend()

plt.show()