def sfine2(mom,leps,thk=254,emax=3.4,minor=0,dofit=4,inorm=[1,1,1],doplot=False): ''' dofit==1: fit only thickness, renorm parameters fixed minor: minim. value of refer. spectrum to include point in chi2 ''' import profit inipars=[thk]+inorm enxz=enx[enx<emax] def zres(pars): model1=profit.plate(enxz,[leps,epssi[enx<emax]],pars[:1]) dif=0 for i in range(len(mom)): dsel=(mom[i]>0)*(enx<emax) if minor>0: dsel*=nor[i]>minor dif+=((mom[i][dsel]*pars[i+1]-model1[dsel[enx<emax]])**2*nor[i][dsel]).sum()*wnor[i] return dif from scipy import optimize as op if dofit==1: fitpars=op.fmin(lambda p:zres(list(p)+inipars[1:]),inipars[:1],disp=0) qpars=inipars[1:] else: fitpars=op.fmin(zres,inipars,disp=0) qpars=fitpars[1:] if doplot: from matplotlib import plot as pl model1=profit.plate(enxz,[leps,epssi[enx<emax]],fitpars[:1]) pl.plot(enxz,model1) for i in range(len(mom)): m=mom[i] pl.plot(enx[(m>0)*(enx<emax)],m[(m>0)*(enx<emax)]*qpars[i],'rgm'[i]) if dofit==1: return fitpars,zres(list(fitpars)+inipars[1:]) else: return fitpars,zres(fitpars)
def plotData(x, *y): colors = ["b","g","r","c","m","y","k"] plt.xlabel("timestamp") plt.ylabel("values") for i in range(len(y)): plt.plot(x, y[i], colors[i%7]) plt.show()
def plot_results(a_plot_list, b_plot_list, k_plot_list, n): # plotting the results of the two algorithms against k value and runtime plt.plot(k_plot_list, a_plot_list, "r-") plt.plot(k_plot_list, b_plot_list, "k-") plt.xlabel("Searching Set Size (k value)") plt.ylabel("Time (seconds)") plt.title(str("Time complexity with data set of size n=" + str(n))) red = mpatches.Patch(color="red", label="Linear Search") black = mpatches.Patch(color="black", label="Binary Search") plt.legend(handles=[red, black]) plt.grid(True) plt.show()
def renorm(preps=[]): qcorr=np.array([ 1.40927795, 1.35854274, 1.53249378]) if (len(preps)==0): #reload xpos=[np.loadtxt(indir+a)[:,0] for a in ls1 if a.find('dark')==0] drk=[np.loadtxt(indir+a)[:,1] for a in ls1 if a.find('dark')==0] ref=[np.loadtxt(indir+a)[:,1] for a in ls1 if a.find('ref')==0] nref=np.array(ref[:3])-np.array(drk) nref[nref<5]=5 preps=[l[:8] for l in ls1 if l.find('_00')>0 and l[:2]=='ti'] ratall=[renor([np.loadtxt(indir+a)[:,1] for a in ls1 if a.find(pf)==0]) for pf in preps] band2,bsel2=cb.gettrans(enx,nref,xpos,smot=0.01,skiplowest=7,rep=1,scale=1/qcorr,spow=1) mom2all=[np.sum([rt[i][bsel2[i]].dot(band2[i])*sior for i in range(3)],axis=0) for rt in ratall] esel*=enx>1.35 ok=[pl.plot(enx[esel],zoo[esel]) for zoo in mom2all[2:-1]] nor=[nref[i][bsel2[i]].dot(band2[i]) for i in range(len(nref))] wnor=[nref[i].sum()/1e4/band2[i].sum() for i in range(len(nref))] locfile="tio2_tl-eps.mat" en2,er,ei=np.genfromtxt("http://physics.muni.cz/~munz/manip/CVD/"+locfile,skip_header=3)[::-1].T epstio=lambda e:ip.interp1d(en2,er)(e)+1j*ip.interp1d(en2,ei)(e) conv1=[ 2.56081863e+02, 8.21570652e-02] allfit=[spectra.fitting(enx[esel],zoo[esel]) for zoo in mom2all[2:-1]] results=np.zeros((len(momall),4)) results[:,0]=[conv1[0]/(f[0][3]+conv1[1]) for f in allfit] results[:,1:]=qcorr restemp=np.zeros_like(results)
### Analysis settings FN = r'D:\measuring\data\20130830\002947_Teleportation_testing_lt1-4_optical_rabi\002947_Teleportation_testing_lt2-9_optical_rabi.hdf5' r = 1 # after which rep to look f = h5py.File(FN, 'r') #channel = f['/HH_channel-1'].value sync_time = f['/HH_sync_time-1'].value sync_nr = f['/HH_sync_nr-1'].value f.close() hist = np.zeros(max(sync_time)) for i in sync_time[where(sync_nr%1000==r)]: hist[i] += 1 fig, ax = subplots(1,1, figsize=((4,4))) plt.plot(hist) ax.set_xlabel('sync time') ax.set_ylabel('counts')
import matplotlib.plot as p import math x = [i/500. for i in range(1000)] f = [math.exp(-x_i) for x_i in x] r = [x_i * f_i for x_i, f_i in zip(x, f)] p.plot(x, r) p.grid() p.show()
from matplotlib import plot as plt x = range(2, 26, 2) y = [1, 2, 3, 4, 5, 6, 7, 8, 20, 12, 12, 11] plt.plot(x, y) plt.show()
import matplotlib.plot as p import math x = [i / 500. for i in range(1000)] f = [math.exp(-x_i) for x_i in x] r = [x_i * f_i for x_i, f_i in zip(x, f)] p.plot(x, r) p.grid() p.show()
#distributution by factors g = sns.FacetGrid(df, row= "factor1",col="factor2", margin_titles=True,size=5) bins = np.linspace(0, 60, 13) g.map(sns.distplot, "x", color="steelblue", bins=bins) #group b plots def fraction_plot(grpvar,ax): grp=df[[grpvar,'colsum','x']].groupby(grpvar).sum() return grp.div(grp['colsum'],0)['x'].plot(kind='bar',ax=ax) fig, axes = plt.subplots(nrows=2, ncols=2,figsize=(30, 15)) #plot iwth confidence interval plt.gca().invert_xaxis() plt.plot(nbrs, fmeanstr, color=c0, label="training"); plt.fill_between(nbrs, fmeanstr - fstdsstr, fmeanstr+fstdsstr, color=c0, alpha=0.3) plt.plot(nbrs, fmeanste, color=c1, label="testing"); plt.fill_between(nbrs, fmeanste - fstdsste, fmeanste+fstdsste, color=c1, alpha=0.5) plt.legend(); ############################### Numpy/Sparse ############################# #add indicator variables based on a categorical column #determine the unique genres genres = set() for genre in largedf.genres: genres.update(genre)
import numpy as np import h5py from matplotlib import plot as plt ### Analysis settings FN = r'D:\measuring\data\20130830\002947_Teleportation_testing_lt1-4_optical_rabi\002947_Teleportation_testing_lt2-9_optical_rabi.hdf5' r = 1 # after which rep to look f = h5py.File(FN, 'r') #channel = f['/HH_channel-1'].value sync_time = f['/HH_sync_time-1'].value sync_nr = f['/HH_sync_nr-1'].value f.close() hist = np.zeros(max(sync_time)) for i in sync_time[where(sync_nr % 1000 == r)]: hist[i] += 1 fig, ax = subplots(1, 1, figsize=((4, 4))) plt.plot(hist) ax.set_xlabel('sync time') ax.set_ylabel('counts')
return data def bbands(self): c = TechIndicators(key=self.api_key, output_format='pandas') data, meta_data = c.get_bbands(symbol=self.stock_name) return data def sma(self): d = TechIndicators(key=self.api_key, output_format='pandas') data, meta_data = d.get_sma(symbol=self.stock_name, time_period=30) return data def close(self): d = TimeSeries(key=self.api_key, output_format='pandas') data, meta_data = d.get_daily(symbol=self.stock_name, outputsize='full') return data if __name__ == "__main__": TI = TechnicalIndicators("AAPL") rsi_data = TI.rsi() plt.plot(rsi_data) plt.show() ts = TimeSeries(key=API_KEY, output_format='pandas') data, meta_data = ts.get_intraday(symbol="MSFT", interval='1min', outputsize='full') data.columns = ["open", "high", "low", "close", "volume"]