def plotFrequency(series, sampRate): """ Plot a frequency to a graph """ s = series / (2.**15) p, freqArray = _fastFourier(s, sampRate) np.plot(freqArray / 1000, 10 * pl.log10(p), color='k') np.xlabel('Frequency (kHz)') np.ylabel('Power (dB)') np.plt.show() return
def Graficar(condiciones): """ genera una grafica a partir de las condiciones de los 10^24 cuerpos Entradas: -condiciones: matriz con las condiciones de la galaxia salidas: """ np.plot(condiciones) return
def Graficar(condiciones): """ genera una grafica a partir de las condiciones de una galaxia en el tiempo T Entradas: -condiciones: matriz con las condiciones de la galaxia salidas: """ np.plot(condiciones) return
def simAll(drunkKinds, walkLengths, numTrials): styleChoice = styleIterator(('m-', 'b--', 'g-.')) for dClass in drunkKinds: curStyle = styleChoice.nextStyle() print('Starting simulation of', dClass.__name__) means = simDrunk(numTrials, dClass, walkLengths) numpy.plot(walkLengths, means, curStyle, label=dClass.__name__) numpy.title('Mean Distance from Origin (' + str(numTrials) + ' trials)') numpy.xlabel('Number of Steps') numpy.ylabel('Distance from Origin') numpy.legend(loc='best')
def plotTone(series, sampRate): """ Plot a tone to a graph """ # Convert sound array to floating point between -1 to 1 snd = series / (2.**15) timeArray = pl.arange(0, snd.shape[0]) timeArray = timeArray / sampRate timeArray = timeArray * 1000 # scales to milliseconds # Plot the tone graph np.plot(timeArray, snd, color='k') np.ylabel('Amplitude') np.xlabel('Time (ms)') np.plt.show() return
def adaptIntPlot(f,a,b): """ Adaptive (doubling partition) integration. Minimizes function evaluations at the expense of some tedious array minipulations. """ maxiter = 20 miniter = 5 tolerance = 0.1 maxnx = 2**maxiter minnx = 2**miniter x = 0.*N.zeros(maxnx) dx = (b-a)/2.#**minsteps nx = 2 x[0] = a x[1] = a+dx integral = N.sum(f(x[1:2]))*dx # 1 so we don't include the first endpt dx /= 2. newintegral = integral/2. + N.sum(f(x[:nx]+dx))*dx for i in range(nx-1,-1,-1): x[2*i] = x[i] x[2*i+1] = x[i] + dx nx *= 2 keepgoing = 1 while keepgoing == 1: integral = newintegral dx /= 2. eff = f(x[:nx]+dx) N.plot(x[:nx]+dx,f(x[:nx]+dx)) newintegral = integral/2. + N.sum(eff)*dx#N.sum(f(x[:nx]+dx))*dx print newintegral*nx/(nx-1) for i in range(nx-1,-1,-1): x[2*i] = x[i] x[2*i+1] = x[i] + dx nx *= 2 keepgoing = 0 if integral*newintegral > 0.: if ((N.fabs(N.log(integral*(nx/2)/(nx/2-1)/(newintegral*nx/(nx-1)))) >\ tolerance) and (nx < maxnx/2)) or (nx < minnx): keepgoing = 1 elif integral*newintegral == 0.: print "Hmmm, we have a zero integral here. Assuming convergence." else: keepgoing = 1 N.show() print nx, if nx == maxnx/2: print 'No convergence in utils.adaptInt!' return newintegral*nx/(nx-1)
def traceWalk(fieldKinds, numSteps): styleChoice = styleIterator(('b+', 'r^', 'ko')) for fClass in fieldKinds: d = UsualDrunk() f = fClass() f.addDrunk(d, Location(0, 0)) locs = [] for s in range(numSteps): f.moveDrunk(d) locs.append(f.getLoc(d)) xVals, yVals = [], [] for loc in locs: xVals.append(loc.getX()) yVals.append(loc.getY()) curStyle = styleChoice.nextStyle() numpy.plot(xVals, yVals, curStyle, label=fClass.__name__) numpy.title('Spots Visited on Walk (' + str(numSteps) + ' steps)') numpy.xlabel('Steps East/West of Origin') numpy.ylabel('Steps North/South of Origin') numpy.legend(loc='best')
def plotLocs(drunkKinds, numSteps, numTrials): styleChoice = styleIterator(('k+', 'r^', 'mo')) for dClass in drunkKinds: locs = getFinalLocs(numSteps, numTrials, dClass) xVals, yVals = [], [] for loc in locs: xVals.append(loc.getX()) yVals.append(loc.getY()) xVals = numpy.array(xVals) yVals = numpy.array(yVals) meanX = sum(abs(xVals)) / len(xVals) meanY = sum(abs(yVals)) / len(yVals) curStyle = styleChoice.nextStyle() numpy.plot(xVals, yVals, curStyle, label = dClass.__name__ +\ ' mean abs dist = <' + str(meanX) + ', ' + str(meanY) + '>') numpy.title('Location at End of Walks (' + str(numSteps) + ' steps)') numpy.ylim(-1000, 1000) numpy.xlim(-1000, 1000) numpy.xlabel('Steps East/West of Origin') numpy.ylabel('Steps North/South of Origin') numpy.legend(loc='lower center')
def gaussian(x, mu, sigma): factor1 = (1.0 / (sigma * ((2 * numpy.pi)**0.5))) factor2 = numpy.e**-(((x - mu)**2) / (2 * sigma**2)) return factor1 * factor2 xVals, yVals = [], [] mu, sigma = 0, 2.5 x = -10 while x <= 10: xVals.append(x) yVals.append(gaussian(x, mu, sigma)) x += 0.05 numpy.plot(xVals, yVals) numpy.title('Normal Distribution, mu = ' + str(mu)\ + ', sigma = ' + str(sigma)) numpy.show() # import scipy.integrate # def checkEmpirical(numTrials): # for t in range(numTrials): # mu = random.randint(-10, 10) # sigma = random.randint(1, 10) # print('For mu =', mu, 'and sigma =', sigma) # for numStd in (1, 1.96, 3): # area = scipy.integrate.quad(gaussian, # mu-numStd*sigma, # mu+numStd*sigma,
#changes the inputs into int variables tIn = float(xInput) rIn = float(yInput) bIn = float(zInput) #xs[0], ys[0], zs[0] = (xIn, yIn, zIn) # Step through "time", calculating the partial derivatives at the current point # and using them to estimate the next point for i in range(count): Xdot, Ydot, Zdot = Lorenz(xs[i], ys[i], zs[i], tIn, rIn, bIn) xs[i + 1] = xs[i] + (Xdot * dt) ys[i + 1] = ys[i] + (Ydot * dt) zs[i + 1] = zs[i] + (Zdot * dt) # Plotting the figure and calling the above functions fig = plt.figure() #setting the projection to 3d np = fig.gca(projection='3d') #plotting the x,y,z values with a 0.4 line width np.plot(xs, ys, zs, lw=0.4) #x, y, z labels np.set_xlabel("X-Axis") np.set_ylabel("Y-Axis") np.set_zlabel("Z-Axis") #tittle name np.set_title("Lorenz Model") #finally plot fucnion plt.show()
def plotDiffs(sampleSizes, diffs, title, label, color='b'): numpy.plot(sampleSizes, diffs, label=label, color=color) numpy.xlabel('Sample Size') numpy.ylabel('% Difference in SD') numpy.title(title) numpy.legend()
predicted_price = predictions[:,i] previous_price = prices[:,length_past+i] previous_prices = prices[:,0:length_past+i] prev_weight = weights #fn(....) new_weight = weights period_return = np.log((new_weight*prices[:,length_past+i+1])/(prev_weight*prices[:,length_past+i])) portfolio_return.append(np.sum(period_return)) prev_weight = new_weight return portfolio_return x = backtest(prices, predictions, initial_weights) np.plot(x) def plot_result(stock_name, normalized_value_p, normalized_value_y_test): newp = denormalize(stock_name, normalized_value_p,predict=True) newy_test = denormalize(stock_name, normalized_value_y_test,predict=False) plt2.plot(newp, color='red', label='Prediction') plt2.plot(newy_test,color='blue', label='Actual') plt2.legend(loc='best') plt2.title('The test result for {}'.format(stock_name)) plt2.xlabel('5 Min ahead Forecast') plt2.ylabel('Price') plt2.show() plot_result("GBP Curncy", p, y_test)
# In[44]: Soal1 import pandas as choi #melakukan import pada library pandas sebagai arjun laptop = { "Nama Laptop": ['Asus', 'ROG', 'Lenovo', 'Samsung'] } #membuat varibel yang bernama laptop, dan mengisi dataframe nama2 laptop x = Arjun.DataFrame( laptop ) #variabel x membuat DataFrame dari library pandas dan akan memanggil variabel laptop. print(' Arjun Punya Laptop ' + x) #print hasil dari x # In[44]: Soal2 import numpy as Arjun #melakukan import numpy sebagai arjun matrix_x = Arjun.eye( 10) #membuat matrix dengan numpy dengan menggunakan fungsi eye matrix_x #deklrasikan matrix_x yang telah dibuat print(matrix_x) #print matrix_x yang telah dibuat dengan 10x10 # In[44]: Soal3 import matplotlib.pyplot as Arjun #import matploblib sebagai arjun Arjun.plot([1, 1, 7, 4, 0, 2, 1]) #memberikan nilai plot atau grafik pada arjun Arjun.xlabel('Arjun Yuda Firwanda') #memberikan label pada x Arjun.ylabel('1174008') #memberikan label pada y Arjun.show() #print hasil plot berbentuk grafik
import numpy as np import matplotlib.pyplot as plt # Input Signal N = 64 k0 = 7 x = np.exp(1j * 2 * np.pi * k0 / N * np.arange(N)) # Array of spectral samples X = np.array([]) for k in range(N): # Create the complex exponential at every frequency s = np.exp(1j * 2 * np.pi * k / N * np.arange(N)) X = np.append(X, sum(x * np.conjugate(s)) # Absolute value of complex signal np.plot(np.arange(N), abs(X)) a = 1+2 b = 1 c = 3 d = 3 f = 3
s = spline(correct_weights, min, max) t = np.arange(min, max, 0.001) y_correto = s(t) #gerando ruído r = np.random(len(t)) r -= 0.5 r *= 100 y_ruidoso = y_correto + r #recuperar informação s_temp = spline(1.0, min, max) B = np.zeros(n, n) for i in range(n): for j in range(n): B[i][j] = s_temp.B_j(i, t[j]) Bt = np.transpose(B) M1 = Bt * B M2 = matrix_m2(n) b = Bt * y_ruidoso M = (M1 + (lamb * M2)) w = np.linalg.solve(M, b) s2 = spline(w, min, max) np.plot(t, s2(t))
#Test X_prim = [] Y_prim = [] def execute(theta): gamma = np.arctan(A[3] / A[2]) alpha = theta - gamma Cz0 = Cz(alpha) Cx0 = Cx(alpha, Cz0) A = A + h * Fonction(A, m, g, gamma, rho, S, Cx0, Cz0, theta, alpha) X_prim.append(A[0]) Y_prim.append(A[1]) for i in range(0, iteration): gamma = np.arctan(A[3] / A[2]) alpha = theta - gamma Cz0 = Cz(alpha) Cx0 = Cx(alpha, Cz0) A = A + h * Fonction(A, m, g, gamma, rho, S, Cx0, Cz0, theta, alpha) X_prim.append(A[0]) Y_prim.append(A[1]) #On récupère les positions à chaque itération print(int(i * 100 / iteration), "%") np.plot(X_prim, Y_prim)
import numpy as np import matplotlib as mpl x = np.linspace(0, 1, 100) y = np.sin(x) np.plot(x, y) np.show()
# #plt.title('Accuracy for different Momentum for CNN') # plt.ylabel('Error') # #plt.ylabel('Accuracy') # plt.xlabel('Momentum') # plt.show() # #For Batch Size # plt.xticks([1 ,2, 3, 4, 5],['1','10','100','500','1000']) # plt.plot([1 ,2, 3, 4, 5],[1.88155 ,1.25564 ,0.43665 ,1.11511 ,3.02981 ], 'bo', label='Training') # plt.plot([1 ,2, 3, 4, 5],[1.88067 ,1.71583 ,0.63323 ,1.07845 ,2.84858 ], 'go', label='Validation') # plt.axis([0, 5.5, 0.0, 3.2]) # plt.legend(loc=0) # plt.title('Cross-Entropy for different batch sizes for CNN') # #plt.title('Accuracy for different batch sizes for CNN') # plt.ylabel('Error') # #plt.ylabel('Accuracy') # plt.xlabel('Batch Size') # plt.show() #For 3.3 plt.xticks([1, 2, 3], ['[2 16]', '[15 16]', '[30 16]']) plt.plot([1, 2, 3], [0.28542, 0.74748, 0.28542], 'bo', label='Training') plt.plot([1, 2, 3], [0.27924, 0.70883, 0.27924], 'go', label='Validation') plt.axis([0.5, 3.5, 0, 0.8]) plt.legend(loc=0) #plt.title('Cross-Entropy for different number of filters in the first layer of CNN') plt.title('Accuracy for different number of filters in the first layer of CNN') #plt.ylabel('Error') plt.ylabel('Accuracy') plt.xlabel('Number of Units') plt.show()
v = v_ah(i, self.ic, self.rn, self.io, self.vo, self.tn) self.i_ah = i self.v_ah = v return i, v if __name__ == '__main__': import pylab as pl t_i = time() path = '../../Cryogenic Probe Station/20140714_nanopillar remeasure/' filename = 'VI_043_VItrace-H_B140211_chip22_jj4_Hset4 4000OeR_40.txt' # low Ic #filename = 'VI_043_VItrace-H_B140211_chip22_jj4_Hset4 4000OeR_70.txt' # high Ic data = np.loadtxt(path + filename) i = data[:, 0] v = data[:, 1] np.plot(i, v, '-') jj = JJIV(i, v) units = np.array([1e-6, 1, 1e-6, 1e-6]) initguess = np.array([10, 1, 0, 30]) * units print(initguess) jj.geticfit2(initguess) print('RSJ fit: ', jj.ic, jj.rn, jj.io, jj.vo) jj.build_ivrsj() pl.plot(jj.irsj, jj.vrsj) pl.draw() # uncomment to fit initguess = pl.array([jj.ic, jj.rn, jj.io, jj.vo, 27]) # add temperature jj.fit_ah_ic(initguess) print('AH fit: ', jj.ic, jj.rn, jj.io, jj.vo, jj.t)