def animate(self, alpha, beta, L, n, div=32, particle='de+'): s = settings.Settings() field = SineField() field.alpha = alpha field.beta = beta field.L = L field.n = n outfile = self.filename(particle, alpha, beta, L, n) s.outfile = outfile with open(s.outpath()) as f: t, x, y, z = extractData(f, [0, 1, 2, 3]) length = len(z) / div for i in xrange(div): start = i * length if i > 0: start = (i-1) * length end = (i+1) * length plt.plot(z[start:end], y[start:end], 'b-', linewidth=1, label=self.label(particle)) xmin, xmax = [ -1.15, 1.15 ] ymin, ymax = [ -1.0, 1.0 ] self.plotField(field, xmin, xmax, ymin, ymax) plt.xlabel('$z$ (m)') plt.ylabel('$y$ (m)') plt.tight_layout() s.outext = '_{index:03}.png'.format(index=i) plt.text(0.25, 0.8, r'$B_z = B_{z0} \left( 1 + \alpha r + \beta z\ \sin (\frac{n \pi z}{L}) \right)$', fontsize=15) plt.text(0.25, 0.7, '$\\alpha = {alp},\\ \\beta = {beta}$'.format(alp=alpha, beta=beta), fontsize=15) plt.savefig(s.outpath()) plt.clf()
def plotSuperimposed(self, alpha, beta, L, n): s = settings.Settings() field = SineField() field.alpha = alpha field.beta = beta field.L = L field.n = n for particle in self.particles: outfile = self.filename(particle, alpha, beta, L, n) s.outfile = outfile with open(s.outpath()) as f: t, x, y, z = extractData(f, [0, 1, 2, 3]) #start = len(z) / 4 + 250 #end = len(z) / 4 + 180 start = 0 end = len(z) plt.plot(z[start:end], y[start:end], self.style[particle], linewidth=1, label=self.label(particle)) xmin, xmax = [ -0.4, 0.4 ] ymin, ymax = [ 0.1, 0.3 ] # xmin, xmax = plt.xlim() # ymin, ymax = plt.ylim() self.plotField(field, xmin, xmax, ymin, ymax) plt.xlabel('$z$ (m)') plt.ylabel('$y$ (m)') # plt.text(0.25, 0.8, r'$B_z = B_{z0} \left( 1 + \alpha r + \beta z\ \sin (\frac{n \pi z}{L}) \right)$', # fontsize=15) # plt.text(0.25, 0.7, '$\\alpha = {alp},\\ \\beta = {beta}$'.format(alp=alpha, beta=beta), # fontsize=15) plt.tight_layout() s.outext = '.pdf' plt.savefig(s.outpath()) plt.show()
def animate(self, alpha, beta, L, n, div=32, particle='de+'): s = settings.Settings() field = SineField() field.alpha = alpha field.beta = beta field.L = L field.n = n outfile = self.filename(particle, alpha, beta, L, n) s.outfile = outfile with open(s.outpath()) as f: t, x, y, z = extractData(f, [0, 1, 2, 3]) length = len(z) / div for i in xrange(div): start = i * length if i > 0: start = (i - 1) * length end = (i + 1) * length plt.plot(z[start:end], y[start:end], 'b-', linewidth=1, label=self.label(particle)) xmin, xmax = [-1.15, 1.15] ymin, ymax = [-1.0, 1.0] self.plotField(field, xmin, xmax, ymin, ymax) plt.xlabel('$z$ (m)') plt.ylabel('$y$ (m)') plt.tight_layout() s.outext = '_{index:03}.png'.format(index=i) plt.text( 0.25, 0.8, r'$B_z = B_{z0} \left( 1 + \alpha r + \beta z\ \sin (\frac{n \pi z}{L}) \right)$', fontsize=15) plt.text(0.25, 0.7, '$\\alpha = {alp},\\ \\beta = {beta}$'.format( alp=alpha, beta=beta), fontsize=15) plt.savefig(s.outpath()) plt.clf()
def plotSuperimposed(self, alpha, beta, L, n): s = settings.Settings() field = SineField() field.alpha = alpha field.beta = beta field.L = L field.n = n for particle in self.particles: outfile = self.filename(particle, alpha, beta, L, n) s.outfile = outfile with open(s.outpath()) as f: t, x, y, z = extractData(f, [0, 1, 2, 3]) #start = len(z) / 4 + 250 #end = len(z) / 4 + 180 start = 0 end = len(z) plt.plot(z[start:end], y[start:end], self.style[particle], linewidth=1, label=self.label(particle)) xmin, xmax = [-0.4, 0.4] ymin, ymax = [0.1, 0.3] # xmin, xmax = plt.xlim() # ymin, ymax = plt.ylim() self.plotField(field, xmin, xmax, ymin, ymax) plt.xlabel('$z$ (m)') plt.ylabel('$y$ (m)') # plt.text(0.25, 0.8, r'$B_z = B_{z0} \left( 1 + \alpha r + \beta z\ \sin (\frac{n \pi z}{L}) \right)$', # fontsize=15) # plt.text(0.25, 0.7, '$\\alpha = {alp},\\ \\beta = {beta}$'.format(alp=alpha, beta=beta), # fontsize=15) plt.tight_layout() s.outext = '.pdf' plt.savefig(s.outpath()) plt.show()