예제 #1
0
	def draw_graph(self):

		n=0
		if (len(self.fx)>0):
			mul,unit=fx_with_units(float(self.fx[len(self.fx)-1]-self.fx[0]))
		else:
			mul=1.0
			unit="Hz"

		fx=[]
		for i in range(0,len(self.fx)):
			fx.append(self.fx[i]*mul)

		self.fig.clf()
		self.fig.subplots_adjust(bottom=0.2)
		self.fig.subplots_adjust(left=0.1)
		self.ax1 = self.fig.add_subplot(111)
		self.ax1.ticklabel_format(useOffset=False)
		#ax2 = ax1.twinx()
		x_pos=0.0
		layer=0
		color =['r','g','b','y','o','r','g','b','y','o']

		self.ax1.set_ylabel(_("Magnitude (Volts)"))

		frequency, = self.ax1.plot(fx,self.mag, 'ro-', linewidth=3 ,alpha=1.0)
		self.ax1.set_xlabel(_("Frequency (")+unit+')')
예제 #2
0
파일: fxmesh.py 프로젝트: xj361685640/gpvdm
    def draw_graph(self):
        my_max = self.fx[0][0]
        my_min = self.fx[0][0]

        for i in range(0, len(self.fx)):
            for ii in range(0, len(self.fx[i])):
                if self.fx[i][ii] > my_max:
                    my_max = self.fx[i][ii]

                if self.fx[i][ii] < my_min:
                    my_min = self.fx[i][ii]

        if (len(self.fx) > 0):
            mul, unit = fx_with_units(float(my_max - my_min))
        else:
            mul = 1.0
            unit = "Hz"

        fx = []

        for i in range(0, len(self.fx)):
            local_fx = []
            for ii in range(0, len(self.fx[i])):
                local_fx.append(self.fx[i][ii] * mul)
            fx.append(local_fx)

        self.fig.clf()
        self.fig.subplots_adjust(bottom=0.2)
        self.fig.subplots_adjust(left=0.1)
        self.ax1 = self.fig.add_subplot(111)
        self.ax1.ticklabel_format(useOffset=False)

        self.ax1.set_ylabel(_("Magnitude") + " (" + _("Volts") + " )")

        for i in range(0, len(fx)):
            frequency, = self.ax1.plot(fx[i],
                                       self.mag[i],
                                       'ro-',
                                       color=get_color(i),
                                       linewidth=3,
                                       alpha=1.0)

        self.ax1.set_xlabel(_("Frequency") + " (" + unit + ")")
예제 #3
0
	def do_plot(self):
		if len(self.data)==0:
			return
		
		if self.data[0].valid_data==False:
			return

		self.fig.clf()
		self.fig.subplots_adjust(bottom=0.2)
		self.fig.subplots_adjust(bottom=0.2)
		self.fig.subplots_adjust(left=0.1)
		self.fig.subplots_adjust(hspace = .001)
		dim=""
		if self.data[0].x_len==1 and self.data[0].z_len==1:
			dim="linegraph"
		elif self.data[0].x_len>1 and self.data[0].y_len>1 and self.data[0].z_len==1:
			if self.data[0].type=="3d":
				dim="wireframe"
			if self.data[0].type=="heat":
				dim="heat"
		elif self.data[0].x_len>1 and self.data[0].y_len>1 and self.data[0].z_len>1:
			print("ohhh full 3D")
			dim="3d"
		else:
			print(_("I don't know how to process this type of file!"),self.data[0].x_len, self.data[0].y_len,self.data[0].z_len)
			return

		title=self.data[0].title
		if self.data[0].time!=-1.0 and self.data[0].Vexternal!=-1.0:
			mul,unit=time_with_units(self.data[0].time)
			title=self.data[0].title+" V="+str(self.data[0].Vexternal)+" "+_("time")+"="+str(self.data[0].time*mul)+" "+unit

		self.fig.suptitle(title)

		self.setWindowTitle(title+" - www.gpvdm.com")

		self.ax=[]


		for i in range(0,len(self.input_files)):
			if dim=="linegraph":
				self.ax.append(self.fig.add_subplot(111,axisbg='white'))
			elif dim=="wireframe":
				self.ax.append(self.fig.add_subplot(111,axisbg='white' ,projection='3d'))
			elif dim=="heat":
				self.ax.append(self.fig.add_subplot(111,axisbg='white'))
			elif dim=="3d":
				self.ax.append(self.fig.add_subplot(111,axisbg='white' ,projection='3d'))
			#Only place label on bottom plot
			#	if self.data[i].type=="3d":
			#else:
			#	self.ax[i].tick_params(axis='x', which='both', bottom='off', top='off',labelbottom='off') # labels along the bottom edge are off

			#Only place y label on center plot
			if self.data[0].normalize==True or self.data[0].norm_to_peak_of_all_data==True:
				y_text="Normalized "+self.data[0].data_label
				data_units="au"
			else:
				data_text=self.data[i].data_label
				data_units=self.data[i].data_units

			if self.data[0].logx==True:
				self.ax[i].set_xscale("log")

			if self.data[0].logy==True:
				self.ax[i].set_yscale("log")


		all_plots=[]
		files=[]
		my_max=1.0

			
		if dim=="linegraph":		#This is for the 1D graph case
			self.ax[0].set_xlabel(self.data[0].x_label+" ("+str(self.data[0].x_units)+")")
			self.ax[0].set_ylabel(self.data[0].data_label+" ("+self.data[0].data_units+")")

			for i in range(0,len(self.input_files)):
				cur_plot, = self.ax[i].plot(self.data[i].y_scale,self.data[i].data[0][0], linewidth=3 ,alpha=1.0,color=get_color(i),marker=get_marker(i))

				if self.labels[i]!="":
					files.append("$"+numbers_to_latex(str(self.labels[i]))+" "+pygtk_to_latex_subscript(self.data[0].key_units)+"$")

				all_plots.append(cur_plot)
				
				if len(self.data[i].labels)!=0:
					for ii in range(0,len(self.data[i].y_scale)):
						fx_unit=fx_with_units(float(self.data[i].labels[ii]))
						label_text=str(float(self.data[i].labels[ii])*fx_unit[0])+" "+fx_unit[1]
						self.ax[i].annotate(label_text,xy = (self.data[i].y_scale[ii], self.data[i].data[0][0][ii]), xytext = (-20, 20),textcoords = 'offset points', ha = 'right', va = 'bottom',bbox = dict(boxstyle = 'round,pad=0.5', fc = 'yellow', alpha = 0.5),arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'))
				#print(self.data[i].labels)
		elif dim=="wireframe":
			self.ax[0].set_xlabel(self.data[0].x_label+" ("+self.data[0].x_units+")")
			self.ax[0].set_ylabel(self.data[0].y_label+" ("+self.data[0].y_units+")")

			for i in range(0,len(self.input_files)):

				#new_data=[[float for y in range(self.data[0].y_len)] for x in range(self.data[0].x_len)]
				#for x in range(0,self.data[i].x_len):
				#	for y in range(0,self.data[i].y_len):
				#		print(x,y,len(self.data[i].data[0]),len(self.data[i].data[0][0]))
				#		new_data[x][y]=self.data[i].data[0][x][y]
				#z = 10 * outer(ones(size(data.x_scale)), cos(data.y_scale))
				#im=self.ax[0].plot_surface(data.x_scale,data.y_scale,z)
				#print(new_data)
				#print(self.data[i].x_scale)
				#print(self.data[i].y_scale)
				X, Y = meshgrid( self.data[i].y_scale,self.data[i].x_scale)
				Z = self.data[i].data[0]

				# Plot the surface
				im=self.ax[i].plot_wireframe( Y,X, Z)

				#pcolor
		elif dim=="heat":
			self.ax[0].set_xlabel(self.data[0].x_label+" ("+self.data[0].x_units+")")
			self.ax[0].set_ylabel(self.data[0].y_label+" ("+self.data[0].y_units+")")

			for i in range(0,len(self.input_files)):

				im=self.ax[0].pcolor(self.data[i].y_scale,self.data[i].x_scale,self.data[i].data[0])
				self.fig.colorbar(im)

				#pcolor

				#self.fig.colorbar(im, shrink=0.5, aspect=5)
				#self.ax[0].plot_surface(x, y, z, rstride=1, cstride=1, cmap=cm.coolwarm,linewidth=0, antialiased=False)
				#self.ax[0].invert_yaxis()
				#self.ax[0].xaxis.tick_top()
		elif dim=="3d":
			self.ax[0].set_xlabel(self.data[0].x_label+" ("+self.data[0].x_units+")")
			self.ax[0].set_ylabel(self.data[0].y_label+" ("+self.data[0].y_units+")")
			self.ax[0].set_zlabel(self.data[0].z_label+" ("+self.data[0].z_units+")")

			for ii in range(0,len(self.data[i].z_scale)):
				my_max,my_min=dat_file_max_min(self.data[i])
				X, Y = meshgrid( self.data[i].x_scale,self.data[i].y_scale)
				new_data=[[float for y in range(self.data[0].y_len)] for x in range(self.data[0].x_len)]
				for x in range(0,self.data[i].x_len):
					for y in range(0,self.data[i].y_len):
						new_data[x][y]=self.data[i].z_scale[ii]+self.data[i].data[ii][x][y]
				self.ax[i].contourf(X, Y, new_data, zdir='z')#

				self.ax[i].set_xlim3d(0, self.data[i].x_scale[-1])
				self.ax[i].set_ylim3d(0, self.data[i].y_scale[-1])
				self.ax[i].set_zlim3d(0, self.data[i].z_scale[-1])

		#setup the key
		if self.data[0].legend_pos=="No key":
			self.ax[i].legend_ = None
		else:
			if len(files)<40:
				self.fig.legend(all_plots, files, self.data[0].legend_pos)
			
		#self.fig.tight_layout(pad=0.0, w_pad=0.0, h_pad=0.0)
		self.fig.canvas.draw()
예제 #4
0
	def do_plot(self):
		print "PLOT TYPE=",self.plot_token.type
		if self.plot_token!=None and len(self.plot_id)!=0:
			plot_number=0

			self.fig.clf()
			self.fig.subplots_adjust(bottom=0.2)
			self.fig.subplots_adjust(bottom=0.2)
			self.fig.subplots_adjust(left=0.1)
			self.fig.subplots_adjust(hspace = .001)

			title=""
			if self.plot_title=="":
				title=self.plot_token.title
			else:
				title=self.plot_title

			if self.plot_token.time!=-1.0 and self.plot_token.Vexternal!=-1.0:
				mul,unit=time_with_units(self.plot_token.time)
				title=title+" V="+str(self.plot_token.Vexternal)+" time="+str(self.plot_token.time*mul)+" "+unit

			self.fig.suptitle(title)

			self.ax=[]
			number_of_plots=max(self.plot_id)+1
			if self.plot_token.type=="heat":
				number_of_plots=1

			if number_of_plots>1:
				yloc = plt.MaxNLocator(4)
			else:
				yloc = plt.MaxNLocator(10)




			for i in range(0,number_of_plots):
				self.ax.append(self.fig.add_subplot(number_of_plots,1,i+1, axisbg='white'))
				#Only place label on bottom plot
				if i==number_of_plots-1:
					print self.plot_token.x_label,self.plot_token.x_units
					self.ax[i].set_xlabel(self.plot_token.x_label+" ("+self.plot_token.x_units+")")
					
				else:
					self.ax[i].tick_params(axis='x', which='both', bottom='off', top='off',labelbottom='off') # labels along the bottom edge are off

				#Only place y label on center plot
				if self.plot_token.normalize==True or self.plot_token.norm_to_peak_of_all_data==True:
					y_text="Normalized "+self.plot_token.y_label
					y_units="au"
				else:
					y_text=self.plot_token.y_label
					y_units=self.plot_token.y_units
				if i==math.trunc(number_of_plots/2):
					self.ax[i].set_ylabel(y_text+" ("+y_units+")")

				if self.plot_token.logx==True:
					self.ax[i].set_xscale("log")

				if self.plot_token.logy==True:
					self.ax[i].set_yscale("log")


			lines=[]
			files=[]

			my_max=1.0
			print "token type==",self.plot_token.type
			if self.plot_token.type=="xy":

				all_max=1.0
				if self.plot_token.norm_to_peak_of_all_data==True:
					m=[]
					my_max=-1e40
					for i in range(0, len(self.input_files)):
						t=[]
						s=[]
						z=[]
						if self.read_data_file(t,s,z,i)==True:
							if max(s)>my_max:
								my_max=max(s)
					all_max=my_max

				for i in range(0, len(self.input_files)):
					#t,s = loadtxt(self.input_files[i], unpack=True)
					t=[]
					s=[]
					z=[]
					if self.read_data_file(t,s,z,i)==True:
						#print "z==",z
						if all_max!=1.0:
							for ii in range(0,len(s)):
								s[ii]=s[ii]/all_max
						print plot_number,len(self.ax)
						#print len(self.ax),plot_number,i,len(self.color),len(self.marker)
						Ec, = self.ax[plot_number].plot(t,s, linewidth=3 ,alpha=1.0,color=self.color[i],marker=self.marker[i])

						#label data if required
						if self.plot_token.label_data==True:
							for ii in range(0,len(t)):
								if z[ii]!="":
									fx_unit=fx_with_units(float(z[ii]))
									label_text=str(float(z[ii])*fx_unit[0])+" "+fx_unit[1]
									self.ax[plot_number].annotate(label_text,xy = (t[ii], s[ii]), xytext = (-20, 20),textcoords = 'offset points', ha = 'right', va = 'bottom',bbox = dict(boxstyle = 'round,pad=0.5', fc = 'yellow', alpha = 0.5),arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0'))

						if number_of_plots>1:
							self.ax[plot_number].yaxis.set_major_formatter(ticker.FormatStrFormatter('%0.1e'))
							if min(s)!=max(s):
								print "TICKS=",(max(s)-min(s))/4.0
								self.ax[plot_number].yaxis.set_ticks(arange(min(s), max(s), (max(s)-min(s))/4.0 ))

						print "roderick",self.labels,i,self.labels[i]
						if self.labels[i]!="":
							#print "Rod=",self.labels[i]
							#print self.plot_token.key_units
							files.append("$"+numbers_to_latex(str(self.labels[i]))+" "+pygtk_to_latex_subscript(self.plot_token.key_units)+"$")

							lines.append(Ec)

				self.lx = None
				self.ly = None
				if self.plot_token.legend_pos=="No key":
					self.ax[plot_number].legend_ = None
				else:
					legend=self.fig.legend(lines, files, self.plot_token.legend_pos)
			elif self.plot_token.type=="3d":
				x=[]
				y=[]
				z=[]
				if read_data_2d(x,y,z,self.input_files[0])==True:

					x_len=len(x)
					y_len=len(y)
					data = zeros((x_len,y_len))
					for xx in range(0,x_len):
						for yy in range(0,y_len):
							data[xx][yy]=z[xx][yy]
					self.ax[0].pcolor(data)

					#self.ax[0].plot_surface(x, y, z, rstride=1, cstride=1, cmap=cm.coolwarm,linewidth=0, antialiased=False)
					#self.ax[0].invert_yaxis()
					#self.ax[0].xaxis.tick_top()
			elif self.plot_token.type=="heat":
				x=[]
				y=[]
				z=[]

				pos=float(self.plot_token.x_start)
				x_step=(float(self.plot_token.x_stop)-float(self.plot_token.x_start))/self.plot_token.x_points
				while(pos<float(self.plot_token.x_stop)):
					x.append(pos)
					pos=pos+x_step

				pos=float(self.plot_token.y_start)
				y_step=(float(self.plot_token.y_stop)-float(self.plot_token.y_start))/self.plot_token.y_points
				while(pos<float(self.plot_token.y_stop)):
					y.append(pos)
					pos=pos+y_step

				data = zeros((len(y),len(x)))

				for ii in range(0,len(self.input_files)):
					t=[]
					s=[]
					z=[]
					if self.read_data_file(t,s,z,ii)==True:
						print self.input_files[ii]
						for points in range(0,len(t)):
							found=0
							if t[points]>x[0]:
								for x_pos in range(0,len(x)):
									if x[x_pos]>t[points]:
										found=found+1
										break

							if s[points]>y[0]:
								for y_pos in range(0,len(y)):
									if y_pos!=0:
										if y[y_pos]>s[points]:
											found=found+1
											break
							if found==2:
								print "adding data at",x_pos,y_pos
								if data[y_pos][x_pos]<10.0:
									data[y_pos][x_pos]=data[y_pos][x_pos]+1
							else:
								print "not adding point",t[points],s[points]

				print x
				print y
				print data
				x_grid, y_grid = mgrid[float(self.plot_token.y_start):float(self.plot_token.y_stop):complex(0, len(y)), float(self.plot_token.x_start):float(self.plot_token.x_stop):complex(0, len(x))]
				self.ax[0].pcolor(y_grid,x_grid,data)

			else:
				x=[]
				y=[]
				z=[]

				if read_data_2d(x,y,z,self.input_files[0])==True:
					maxx=-1
					maxy=-1
					for i in range(0,len(z)):
						if x[i]>maxx:
							maxx=x[i]

						if y[i]>maxy:
							maxy=y[i]

					maxx=maxx+1
					maxy=maxy+1

					data = zeros((maxy,maxx))


					for i in range(0,len(z)):
						data[y[i]][x[i]]= random.random()+5
						self.ax[0].text(x[i], y[i]+float(maxy)/float(len(z))+0.1,'%.1e' %  z[i], fontsize=12)

					#fig, ax = plt.subplots()
					self.ax[0].pcolor(data,cmap=plt.cm.Blues)

					self.ax[0].invert_yaxis()
					self.ax[0].xaxis.tick_top()

			#self.fig.tight_layout(pad=0.0, w_pad=0.0, h_pad=0.0)
			self.fig.canvas.draw()
			print "exit do plot"