Example #1
0
			# Red for Halton sequence
			# Green for normal random numbers
			# Blue for points on a hypersphere
			ax1.plot(x[0], x[1], 'o', color=(1,0,0))
			ax1.plot(xn[0], xn[1], 'o', color=(0,1,0))
			ax1.plot(xs[0], xs[1], 'o', color=(0,0,1))
			
			ii+=1
		
		if mskips>0:
			print "# of skipped points due to s>=1   :", mskips
		if rskips>0:
			print "# of skipped points due to small r:", rskips
		
		ax1.set_xlim(-1.2, 1.2)
		ax1.set_ylim(-1.2, 1.2)
		
		ax1.grid(True)
		
		ax1.hold(False)
		
		# Draw figure on screen
		pyopl.draw(f1)
		
		# Unlock GUI
		pyopl.lock(False)
		
		# Handle keyboard interrupts properly.
		pyopl.join()
	
	
Example #2
0
	def __call__(self, prefixText='', postfixText='', createPlots=True, initalizePlotting=True):
		try:
			# Initialize plotting system
			if initalizePlotting:
				pyopl.init()

			# Lock GUI
			pyopl.lock()
				
			# Are we creating plots?
			if createPlots: 
				# Check if figures were created and are alive, add missing figures to a list
				graphsToCreate=[]
				for (graphName, graph) in self.setup['graphs'].iteritems():
					if graphName not in self.figure:
						if self.debug:
							DbgMsgOut("WxMplPL", "Added missing graph (not in figure list) '"+graphName+"'.")
						graphsToCreate.append(graphName)
					elif not pyopl.alive(self.figure[graphName]): 
						if self.debug:
							DbgMsgOut("WxMplPL", "Added missing graph (not in on screen) '"+graphName+"'.")
						graphsToCreate.append(graphName)
				
				# Unlock GUI
				pyopl.lock(False)
				
				# OK, now create figures and store the tags
				for graphName in graphsToCreate:
					if self.debug:
						DbgMsgOut("WxMplPL", "  Creating figure for '"+graphName+"'")
					graph=self.setup['graphs'][graphName]
					
					fig=pyopl.figure(**(graph['shape']))
					self.figure[graphName]=fig
					pyopl.title(fig, graphName+" : "+graph['title'])
				
				# Lock GUI
				pyopl.lock(True)
				
				# Add axes to created graphs
				for graphName in graphsToCreate:
					if self.debug:
						DbgMsgOut("WxMplPL", "  Creating axes for '"+graphName+"'")
					
					# Get graph data
					graph=self.setup['graphs'][graphName]
					
					# Get figure
					fig=self.figure[graphName]
					
					# Check if it is alive
					if not pyopl.alive(fig):
						if self.debug:
							DbgMsgOut("WxMplPL", "    Figure not alive, skipped.")
						continue
					
					# Create axes
					axesDict={}
					for (axName, ax) in graph['axes'].iteritems():
						if self.debug:
							DbgMsgOut("WxMplPL", "    '"+axName+"'")
						opt=ax.get('options', {})
						# Handle polar axes
						if ax.get('gridtype', None)=='polar':
							opt.update(projection='polar')
						
						# Create axes
						if 'rectangle' in ax:
							axesDict[axName]=fig.add_axes(ax['rectangle'], **opt)
						elif 'subplot' in ax:
							axesDict[axName]=fig.add_subplot(*(ax['subplot']), **opt)
						else:
							axesDict[axName]=fig.add_axes((0.12, 0.12, 0.76, 0.76), **opt)
						
					# Put axes dict in self.plotAxes
					self.plotAxes[graphName]=axesDict

			# Go through all graphs
			for (graphName, graph) in self.setup['graphs'].iteritems():
				if self.debug:
					DbgMsgOut("WxMplPL", "Refreshing graph '"+graphName+"'")
				
				# Get figure
				fig=self.figure[graphName]
					
				# Check if it is alive
				if not pyopl.alive(fig):
					if self.debug:
						DbgMsgOut("WxMplPL", "  Figure not alive, skipped.")
					continue
				
				# Go through axes and add data.
				for (axName, axobj) in self.plotAxes[graphName].iteritems(): 
					if self.debug:
						DbgMsgOut("WxMplPL", "  Refreshing axes '"+axName+"'")
					
					# Get axes data 
					ax=graph['axes'][axName]
					
					# Clear axes
					axobj.clear()
					
					# Go through all traces on these axes
					for traceName in self.tracesOnAxes[(graphName, axName)]: 
						if self.debug:
							DbgMsgOut("WxMplPL", "    Refreshing trace '"+traceName+"'")
							
						trace=self.setup['traces'][traceName]
						xresult=trace['xresult']
						yresult=trace['yresult']
						
						# Go through all corners
						for cornerName in self.compiledCornerNames[traceName]: 
							if self.debug:
								DbgMsgOut("WxMplPL", "      in corner '"+cornerName+"'")
								
							# Get xresult and yresult
							if xresult in self.pe.results and cornerName in self.pe.results[xresult]: 
								x=self.pe.results[xresult][cornerName]
							else:
								x=None
								
							if yresult in self.pe.results and cornerName in self.pe.results[yresult]: 
								y=self.pe.results[yresult][cornerName]
							else:
								y=None
							
							# Calculate style
							style=self._traceStyle(traceName, trace, cornerName)
							
							# Set name
							style['label']=cornerName+'.'+traceName
							
							# Plot (TODO: handle polar plots correctly, need r, phi from x, y)
							if x is not None and y is not None: 
								axobj.plot(x, y, **style)
					
					if self.debug:
						DbgMsgOut("WxMplPL", "  Finalizing axes settings for '"+axName+"'")
						
					# Handle log scale
					if ax.get('gridtype', None)=='polar':
						pass
					else:
						# Rectilinear grid, handle log scale
						
						# x-axis
						xscale=ax.get('xscale', None) 
						kwargs={}
						if xscale is None:
							type='linear'
						else:
							if xscale.get('type', None)=='log':
								type='log'
								
								if 'linthresh' in xscale:
									type='symlog'
									kwargs['linthreshx']=xscale['linthresh']
								
								if 'base' in xscale:
									kwargs['basex']=xscale['base']
								else:
									kwargs['basex']=10
								
								if 'subticks' in xscale:
									kwargs['subsx']=xscale['subticks']
								elif kwargs['basex']==10:
									kwargs['subsx']=self.log10minors
								elif kwargs['basex']==2:
									kwargs['subsx']=self.log2minors
							else:
								type='linear'
						axobj.set_xscale(type, **kwargs)
						
						# y-axis
						yscale=ax.get('yscale', None) 
						kwargs={}
						if yscale is None:
							type='linear'
						else:
							if yscale.get('type', None)=='log':
								if 'linthresh' in yscale:
									type='symlog'
									kwargs['linthreshy']=yscale['linthresh']
								
								if 'base' in yscale:
									kwargs['basey']=yscale['base']
								else:
									kwargs['basey']=10
								
								if 'subticks' in yscale:
									kwargs['subsy']=yscale['subticks']
								elif kwargs['basey']==10:
									kwargs['subsy']=self.log10minors
								elif kwargs['basey']==2:
									kwargs['subsy']=self.log2minors
							else:
								type='linear'
						axobj.set_yscale(type, **kwargs)
						
					# Labels, title, legend, grid
					ax=graph['axes'][axName]
					if 'xlabel' in ax:
						axobj.set_xlabel(ax['xlabel'])
					if 'ylabel' in ax:
						axobj.set_ylabel(ax['ylabel'])
					if 'title' in ax:
						axobj.set_title(ax['title'])
					if 'legend' in ax and ax['legend']:
						axobj.legend()
					if 'grid' in ax:
						axobj.grid(ax['grid'])
						
					# Set axis limits
					if 'xlimits' in ax:
						axobj.set_xlim(ax['xlimits'])
					if 'ylimits' in ax:
						axobj.set_ylim(ax['ylimits'])
						
				# TODO: xlimits and ylimits on polar axes
				
				if self.debug:
					DbgMsgOut("WxMplPL", "Finalizing graph '"+graphName+"'.")
					
				# Set plot and window title
				if len(prefixText)>0:
					prefix=prefixText+' : '
				else:
					prefix=''
				if len(postfixText)>0:
					postfix=' : '+postfixText
				else:
					postfix=''
				if 'title' in graph:
					gt=graph['title']
				else:
					gt=''
				
				if not graphName in self.titleArtist:
					self.titleArtist[graphName]=fig.suptitle(prefix+gt+postfix)
				else:
					self.titleArtist[graphName].set_text(prefix+gt+postfix)
				
				# Draw the figure
				pyopl.draw(fig)
			
			# Unlock GUI
			pyopl.lock(False)
		
		except (KeyboardInterrupt, SystemExit):
			pyopl.lock(False)
			raise
Example #3
0
            # Red for Halton sequence
            # Green for normal random numbers
            # Blue for points on a hypersphere
            ax1.plot(x[0], x[1], 'o', color=(1, 0, 0))
            ax1.plot(xn[0], xn[1], 'o', color=(0, 1, 0))
            ax1.plot(xs[0], xs[1], 'o', color=(0, 0, 1))

            ii += 1

        if mskips > 0:
            print "# of skipped points due to s>=1   :", mskips
        if rskips > 0:
            print "# of skipped points due to small r:", rskips

        ax1.set_xlim(-1.2, 1.2)
        ax1.set_ylim(-1.2, 1.2)

        ax1.grid(True)

        ax1.hold(False)

        # Draw figure on screen
        pyopl.draw(f1)

        # Unlock GUI
        pyopl.lock(False)

        # Handle keyboard interrupts properly.
        pyopl.join()
Example #4
0
    def __call__(self,
                 prefixText='',
                 postfixText='',
                 createPlots=True,
                 initalizePlotting=True):
        try:
            # Initialize plotting system
            if initalizePlotting:
                pyopl.init()

            # Lock GUI
            pyopl.lock()

            # Are we creating plots?
            if createPlots:
                # Check if figures were created and are alive, add missing figures to a list
                graphsToCreate = []
                for (graphName, graph) in self.setup['graphs'].iteritems():
                    if graphName not in self.figure:
                        if self.debug:
                            DbgMsgOut(
                                "WxMplPL",
                                "Added missing graph (not in figure list) '" +
                                graphName + "'.")
                        graphsToCreate.append(graphName)
                    elif not pyopl.alive(self.figure[graphName]):
                        if self.debug:
                            DbgMsgOut(
                                "WxMplPL",
                                "Added missing graph (not in on screen) '" +
                                graphName + "'.")
                        graphsToCreate.append(graphName)

                # Unlock GUI
                pyopl.lock(False)

                # OK, now create figures and store the tags
                for graphName in graphsToCreate:
                    if self.debug:
                        DbgMsgOut("WxMplPL",
                                  "  Creating figure for '" + graphName + "'")
                    graph = self.setup['graphs'][graphName]

                    fig = pyopl.figure(**(graph['shape']))
                    self.figure[graphName] = fig
                    pyopl.title(fig, graphName + " : " + graph['title'])

                # Lock GUI
                pyopl.lock(True)

                # Add axes to created graphs
                for graphName in graphsToCreate:
                    if self.debug:
                        DbgMsgOut("WxMplPL",
                                  "  Creating axes for '" + graphName + "'")

                    # Get graph data
                    graph = self.setup['graphs'][graphName]

                    # Get figure
                    fig = self.figure[graphName]

                    # Check if it is alive
                    if not pyopl.alive(fig):
                        if self.debug:
                            DbgMsgOut("WxMplPL",
                                      "    Figure not alive, skipped.")
                        continue

                    # Create axes
                    axesDict = {}
                    for (axName, ax) in graph['axes'].iteritems():
                        if self.debug:
                            DbgMsgOut("WxMplPL", "    '" + axName + "'")
                        opt = ax.get('options', {})
                        # Handle polar axes
                        if ax.get('gridtype', None) == 'polar':
                            opt.update(projection='polar')

                        # Create axes
                        if 'rectangle' in ax:
                            axesDict[axName] = fig.add_axes(
                                ax['rectangle'], **opt)
                        elif 'subplot' in ax:
                            axesDict[axName] = fig.add_subplot(
                                *(ax['subplot']), **opt)
                        else:
                            axesDict[axName] = fig.add_axes(
                                (0.12, 0.12, 0.76, 0.76), **opt)

                    # Put axes dict in self.plotAxes
                    self.plotAxes[graphName] = axesDict

            # Go through all graphs
            for (graphName, graph) in self.setup['graphs'].iteritems():
                if self.debug:
                    DbgMsgOut("WxMplPL",
                              "Refreshing graph '" + graphName + "'")

                # Get figure
                fig = self.figure[graphName]

                # Check if it is alive
                if not pyopl.alive(fig):
                    if self.debug:
                        DbgMsgOut("WxMplPL", "  Figure not alive, skipped.")
                    continue

                # Go through axes and add data.
                for (axName, axobj) in self.plotAxes[graphName].iteritems():
                    if self.debug:
                        DbgMsgOut("WxMplPL",
                                  "  Refreshing axes '" + axName + "'")

                    # Get axes data
                    ax = graph['axes'][axName]

                    # Clear axes
                    axobj.clear()

                    # Go through all traces on these axes
                    for traceName in self.tracesOnAxes[(graphName, axName)]:
                        if self.debug:
                            DbgMsgOut(
                                "WxMplPL",
                                "    Refreshing trace '" + traceName + "'")

                        trace = self.setup['traces'][traceName]
                        xresult = trace['xresult']
                        yresult = trace['yresult']

                        # Go through all corners
                        for cornerName in self.compiledCornerNames[traceName]:
                            if self.debug:
                                DbgMsgOut(
                                    "WxMplPL",
                                    "      in corner '" + cornerName + "'")

                            # Get xresult and yresult
                            if xresult in self.pe.results and cornerName in self.pe.results[
                                    xresult]:
                                x = self.pe.results[xresult][cornerName]
                            else:
                                x = None

                            if yresult in self.pe.results and cornerName in self.pe.results[
                                    yresult]:
                                y = self.pe.results[yresult][cornerName]
                            else:
                                y = None

                            # Calculate style
                            style = self._traceStyle(traceName, trace,
                                                     cornerName)

                            # Set name
                            style['label'] = cornerName + '.' + traceName

                            # Plot (TODO: handle polar plots correctly, need r, phi from x, y)
                            if x is not None and y is not None:
                                axobj.plot(x, y, **style)

                    if self.debug:
                        DbgMsgOut(
                            "WxMplPL",
                            "  Finalizing axes settings for '" + axName + "'")

                    # Handle log scale
                    if ax.get('gridtype', None) == 'polar':
                        pass
                    else:
                        # Rectilinear grid, handle log scale

                        # x-axis
                        xscale = ax.get('xscale', None)
                        kwargs = {}
                        if xscale is None:
                            type = 'linear'
                        else:
                            if xscale.get('type', None) == 'log':
                                type = 'log'

                                if 'linthresh' in xscale:
                                    type = 'symlog'
                                    kwargs['linthreshx'] = xscale['linthresh']

                                if 'base' in xscale:
                                    kwargs['basex'] = xscale['base']
                                else:
                                    kwargs['basex'] = 10

                                if 'subticks' in xscale:
                                    kwargs['subsx'] = xscale['subticks']
                                elif kwargs['basex'] == 10:
                                    kwargs['subsx'] = self.log10minors
                                elif kwargs['basex'] == 2:
                                    kwargs['subsx'] = self.log2minors
                            else:
                                type = 'linear'
                        axobj.set_xscale(type, **kwargs)

                        # y-axis
                        yscale = ax.get('yscale', None)
                        kwargs = {}
                        if yscale is None:
                            type = 'linear'
                        else:
                            if yscale.get('type', None) == 'log':
                                if 'linthresh' in yscale:
                                    type = 'symlog'
                                    kwargs['linthreshy'] = yscale['linthresh']

                                if 'base' in yscale:
                                    kwargs['basey'] = yscale['base']
                                else:
                                    kwargs['basey'] = 10

                                if 'subticks' in yscale:
                                    kwargs['subsy'] = yscale['subticks']
                                elif kwargs['basey'] == 10:
                                    kwargs['subsy'] = self.log10minors
                                elif kwargs['basey'] == 2:
                                    kwargs['subsy'] = self.log2minors
                            else:
                                type = 'linear'
                        axobj.set_yscale(type, **kwargs)

                    # Labels, title, legend, grid
                    ax = graph['axes'][axName]
                    if 'xlabel' in ax:
                        axobj.set_xlabel(ax['xlabel'])
                    if 'ylabel' in ax:
                        axobj.set_ylabel(ax['ylabel'])
                    if 'title' in ax:
                        axobj.set_title(ax['title'])
                    if 'legend' in ax and ax['legend']:
                        axobj.legend()
                    if 'grid' in ax:
                        axobj.grid(ax['grid'])

                    # Set axis limits
                    if 'xlimits' in ax:
                        axobj.set_xlim(ax['xlimits'])
                    if 'ylimits' in ax:
                        axobj.set_ylim(ax['ylimits'])

                # TODO: xlimits and ylimits on polar axes

                if self.debug:
                    DbgMsgOut("WxMplPL",
                              "Finalizing graph '" + graphName + "'.")

                # Set plot and window title
                if len(prefixText) > 0:
                    prefix = prefixText + ' : '
                else:
                    prefix = ''
                if len(postfixText) > 0:
                    postfix = ' : ' + postfixText
                else:
                    postfix = ''
                if 'title' in graph:
                    gt = graph['title']
                else:
                    gt = ''

                if not graphName in self.titleArtist:
                    self.titleArtist[graphName] = fig.suptitle(prefix + gt +
                                                               postfix)
                else:
                    self.titleArtist[graphName].set_text(prefix + gt + postfix)

                # Draw the figure
                pyopl.draw(fig)

            # Unlock GUI
            pyopl.lock(False)

        except (KeyboardInterrupt, SystemExit):
            pyopl.lock(False)
            raise