From: Gabor K. <Kal...@ms...> - 2008-09-11 12:28:56
|
For semi-log plots: How can one "fool" Vpython to display y=f(log10(x)) ? See sample program below ****** from visual import * from visual.graph import * graph1=gdisplay(x=0,y=0, width=400,height=200,title="FFT",xtitle="n-th", ytitle="ampl",xmax=20,xmin=0,ymax=200,ymin=0, foreground=color.black,background=color.white) plot1 = gvbars(delta=0.5, color=color.green) import numarray.fft.fftpack as fftpack from scipy import * import math npts=4096 #Use some power of 2 t=linspace(0,1,npts+1) dt = (t[-1]-t[0])/(len(t)-1) # Maximum frequency is 1/dt ? fmax = 1/(2*dt) sig=[] for i in range(0,npts+1): if i<0.5*npts: sig.append(100.) else: sig.append(-100) #f1 = 400 #sig=2*sin(2*pi*f1*t)+0.5*sin(2*pi*5*f1*t) ft = fft(sig,n=npts) coeff=pi*2**(log10(npts)/log10(2)-3) mgft=abs(ft)/coeff ) df = fmax/float(npts/2) f=(linspace(0,fmax,0.5*npts+1)) for i in range(1,21): plot1.plot(pos=(f[i],mgft[i])) print "done" |