示例#1
0
import pyopus.wxmplplot as pyopl
from numpy import arange, sin, cos, exp, pi, e

if __name__ == '__main__':
    # Initialize gui thread, clean up.
    pyopl.init()
    pyopl.close()

    # Plot data - sin(x), cos(x), exp(x/pi) .. for x in [0, 2pi] with 0.2 step.
    x = arange(0.0, 2 * pi, 0.2)
    y1 = sin(x)
    y2 = cos(x)
    y3 = exp(x / pi)

    # Plot window
    f1 = pyopl.figure(windowTitle="Subplots", figpx=(600, 600), dpi=100)

    # Lock GUI
    pyopl.lock(True)

    # Check if figure is alive
    if pyopl.alive(f1):
        # Create 2 subplots, vertical stack of 2
        ax1 = f1.add_subplot(2, 1, 1)
        ax2 = f1.add_subplot(2, 1, 2)

        # First axes
        ax1.hold(True)
        ax1.plot(x, y1, '-o', label='sin(x)', color=(1, 0, 0))
        ax1.plot(x, 2 * y1, '-o', label='2sin(x)', color=(1, 0, 0))
        ax1.grid(True)
示例#2
0
from numpy import arange, sin, cos, exp, pi, e

if __name__ == '__main__':
    # Initialize gui thread, clean up.
    pyopl.init()
    pyopl.close()

    # Plot data - sin(x), cos(x), exp(x/pi) .. for x in [0, 2pi] with 0.2 step.
    x = arange(0.0, 2 * pi, 0.2)
    y1 = sin(x)
    y2 = cos(x)
    y3 = exp(x / pi)

    # Create first figure (plot window). This is now the active figure.
    f1 = pyopl.figure(windowTitle="Figure - single axes",
                      figpx=(600, 400),
                      dpi=100)

    # Lock GUI
    pyopl.lock(True)

    # Check if figure is alive
    if pyopl.alive(f1):
        # Create axes that will take a 76% x 76% area of the figure.
        # The bottom left corner of the axes is at 12% of figure height and
        # width measured from the bottom left corner of the figure.
        ax1 = f1.add_axes((0.12, 0.12, 0.76, 0.76))

        # Add first trace (x, y1).
        # Solid line, points marked with o.
        # Color is a (r,g,b) tuple.
示例#3
0
import pyopus.wxmplplot as pyopl
from numpy import arange, sin, cos, exp, pi, e

if __name__ == '__main__':
    # Initialize gui thread, clean up.
    pyopl.init()
    pyopl.close()

    # Plot data - sin(x), cos(x), exp(x/pi) .. for x in [0, 2pi] with 0.2 step.
    t = arange(0.0, 10 * pi, 0.2)
    r = 2 * pi / (2 * pi + t)
    y = sin(t) * r
    x = cos(t) * r

    # Plot window
    f1 = pyopl.figure(windowTitle="Annotations", figpx=(800, 400), dpi=100)

    # Lock GUI
    pyopl.lock(True)

    # Check if figure is alive
    if pyopl.alive(f1):
        # Create 2 subplots, horizontal stack of 2
        ax1 = f1.add_subplot(2, 1, 1)
        ax2 = f1.add_subplot(2, 1, 2)

        # First axes
        ax1.hold(True)
        ax1.plot(t, x, '-', label='cos(t)*r(t)', color=(1, 0, 0))
        ax1.plot(t, y, '-', label='sin(t)*r(t)', color=(0, 0.5, 0))
        ax1.grid(True)
示例#4
0
import pyopus.wxmplplot as pyopl
from numpy import arange, sin, cos, exp, pi, e

if __name__ == '__main__':
	# Initialize gui thread, clean up. 
	pyopl.init()
	pyopl.close()

	# Plot data - sin(x), cos(x), exp(x/pi) .. for x in [0, 2pi] with 0.2 step. 
	t = arange(0.0, 10*pi, 0.2)
	r = 100/(10+t)
	y = sin(t)*r
	x = cos(t)*r
	
	# Plot window
	f1=pyopl.figure(windowTitle="xy and polar plot", figpx=(800,400), dpi=100)
	
	# Lock GUI
	pyopl.lock(True)
	
	# Check if figure is alive
	if pyopl.alive(f1):
		# Create 2 subplots, horizontal stack of 2
		ax1=f1.add_subplot(1,2,1, aspect='equal')	# Equal aspect ratio
		ax2=f1.add_subplot(1,2,2, aspect='equal', projection='polar')	# Equal aspect ratio, polar plot
		
		# First axes
		ax1.hold(True)
		ax1.plot(x, y, '-', label='sin(x)', color=(1,0,0))
		ax1.grid(True)
		ax1.set_xlabel('x')
示例#5
0
import pyopus.wxmplplot as pyopl
from numpy import arange, sin, cos, exp, pi, e

if __name__ == '__main__':
    # Initialize gui thread, clean up.
    pyopl.init()
    pyopl.close()

    # Plot data - sin(x), cos(x), exp(x/pi) .. for x in [0, 2pi] with 0.2 step.
    x = arange(0.0, 2 * pi, 0.2)
    y1 = sin(x)
    y2 = cos(x)
    y3 = exp(x / pi)

    # Plot window
    f1 = pyopl.figure(windowTitle="Scaling", figpx=(800, 400), dpi=100)

    # Lock GUI
    pyopl.lock(True)

    # Check if figure is alive
    if pyopl.alive(f1):
        # Create 2 subplots, horizontal stack of 2
        ax1 = f1.add_subplot(1, 2, 1)
        ax2 = f1.add_subplot(1, 2, 2)

        # First axes
        ax1.hold(True)
        ax1.plot(x, y1, '-o', label='sin(x)', color=(1, 0, 0))
        ax1.plot(x, 2 * y1, '-o', label='2sin(x)', color=(1, 0, 0))
        ax1.grid(True)
示例#6
0
import pyopus.wxmplplot as pyopl
from numpy import arange, sin, cos, exp, pi, e

if __name__ == '__main__':
	# Initialize gui thread, clean up.
	pyopl.init()
	pyopl.close()

	# Plot data - sin(x), cos(x), exp(x/pi) .. for x in [0, 2pi] with 0.2 step.
	t = arange(0.0, 10*pi, 0.2)
	r = 2*pi/(2*pi+t)
	y = sin(t)*r
	x = cos(t)*r

	# Plot window
	f1=pyopl.figure(windowTitle="Annotations", figpx=(800,400), dpi=100)

	# Lock GUI
	pyopl.lock(True)

	# Check if figure is alive
	if pyopl.alive(f1):
		# Create 2 subplots, horizontal stack of 2
		ax1=f1.add_subplot(2,1,1)
		ax2=f1.add_subplot(2,1,2)

		# First axes
		ax1.hold(True)
		ax1.plot(t, x, '-', label='cos(t)*r(t)', color=(1,0,0))
		ax1.plot(t, y, '-', label='sin(t)*r(t)', color=(0,0.5,0))
		ax1.grid(True)
示例#7
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
示例#8
0
    nn = int(np.ceil(n / 2) * 2)

    # Halton/Sobol sequence generator
    gen = ghalton.Halton(nn)
    # gen=sobol.Sobol(nn)

    # Skip first nn entries
    gen.get(nn)

    # Initialize gui thread, clean up.
    pyopl.init()
    pyopl.close()

    # Create first figure (plot window). This is now the active figure.
    f1 = pyopl.figure(windowTitle="Random points inside a disc",
                      figpx=(600, 400),
                      dpi=100)

    # Lock GUI
    pyopl.lock(True)

    # Check if figure is alive
    if pyopl.alive(f1):
        ax1 = f1.add_axes((0.12, 0.12, 0.76, 0.76))

        ax1.hold(True)

        ii = 0
        rskips = 0
        mskips = 0
        while ii < 150:
示例#9
0
import pyopus.wxmplplot as pyopl
from numpy import arange, sin, cos, exp, pi, e

if __name__ == '__main__':
	# Initialize gui thread, clean up. 
	pyopl.init()
	pyopl.close()

	# Plot data - sin(x), cos(x), exp(x/pi) .. for x in [0, 2pi] with 0.2 step. 
	x = arange(0.0, 2*pi, 0.2)
	y1 = sin(x)
	y2 = cos(x)
	y3 = exp(x/pi)
	
	# Plot window
	f1=pyopl.figure(windowTitle="Manually sized subplots", figpx=(600,600), dpi=100)
	
	# Lock GUI
	pyopl.lock(True)
	
	# Check if figure is alive
	if pyopl.alive(f1):
		# Create 2 subplots, vertical stack of 2, 40%+60% height
		# (x0, y0, w, h) ... 
		#   x=0 .. left,  y=0 .. bottom
		#   x=1 .. right, y=1 .. top 
		ax1=f1.add_axes((0.1,0.1,0.8,0.25)) # 10% left, right, and bottom margin, 5% top margin
		ax2=f1.add_axes((0.1,0.45,0.8,0.45)) # 10% left, right, and top margin, 5% bottom margin
		
		# First axes
		ax1.hold(True)
示例#10
0
from numpy import arange, sin, cos, exp, pi, e

if __name__ == '__main__':
    # Initialize gui thread, clean up.
    pyopl.init()
    pyopl.close()

    # Plot data - sin(x), cos(x), exp(x/pi) .. for x in [0, 2pi] with 0.2 step.
    x = arange(0.0, 2 * pi, 0.2)
    y1 = sin(x)
    y2 = cos(x)
    y3 = exp(x / pi)

    # Plot window
    f1 = pyopl.figure(windowTitle="Manually sized subplots",
                      figpx=(600, 600),
                      dpi=100)

    # Lock GUI
    pyopl.lock(True)

    # Check if figure is alive
    if pyopl.alive(f1):
        # Create 2 subplots, vertical stack of 2, 40%+60% height
        # (x0, y0, w, h) ...
        #   x=0 .. left,  y=0 .. bottom
        #   x=1 .. right, y=1 .. top
        ax1 = f1.add_axes(
            (0.1, 0.1, 0.8,
             0.25))  # 10% left, right, and bottom margin, 5% top margin
        ax2 = f1.add_axes(
示例#11
0
from numpy import arange, sin, cos, exp, pi, e

if __name__ == '__main__':
    # Initialize gui thread, clean up.
    pyopl.init()
    pyopl.close()

    # Plot data - sin(x), cos(x), exp(x/pi) .. for x in [0, 2pi] with 0.2 step.
    t = arange(0.0, 10 * pi, 0.2)
    r = 100 / (10 + t)
    y = sin(t) * r
    x = cos(t) * r

    # Plot window
    f1 = pyopl.figure(windowTitle="xy and polar plot",
                      figpx=(800, 400),
                      dpi=100)

    # Lock GUI
    pyopl.lock(True)

    # Check if figure is alive
    if pyopl.alive(f1):
        # Create 2 subplots, horizontal stack of 2
        ax1 = f1.add_subplot(1, 2, 1, aspect='equal')  # Equal aspect ratio
        ax2 = f1.add_subplot(
            1, 2, 2, aspect='equal',
            projection='polar')  # Equal aspect ratio, polar plot

        # First axes
        ax1.hold(True)
示例#12
0
import pyopus.wxmplplot as pyopl
from numpy import arange, sin, cos, exp, pi, e

if __name__ == '__main__':
	# Initialize gui thread, clean up. 
	pyopl.init()
	pyopl.close()

	# Plot data - sin(x), cos(x), exp(x/pi) .. for x in [0, 2pi] with 0.2 step. 
	x = arange(0.0, 2*pi, 0.2)
	y1 = sin(x)
	y2 = cos(x)
	y3 = exp(x/pi)
	
	# Plot window
	f1=pyopl.figure(windowTitle="Subplots", figpx=(600,600), dpi=100)
	
	# Lock GUI
	pyopl.lock(True)
	
	# Check if figure is alive
	if pyopl.alive(f1):
		# Create 2 subplots, vertical stack of 2
		ax1=f1.add_subplot(2,1,1)
		ax2=f1.add_subplot(2,1,2)
	
		# First axes
		ax1.hold(True)
		ax1.plot(x, y1, '-o', label='sin(x)', color=(1,0,0))
		ax1.plot(x, 2*y1, '-o', label='2sin(x)', color=(1,0,0))
		ax1.grid(True)
示例#13
0
文件: an.py 项目: xanderhsia/pyopus
	f.close()
	
	print summary
	
	findex=0
	popsize=10
	runindex=0
	
	f=open("fhist_f%d_p%d_r%d.pck" % (findex, popsize, runindex), "rb")
	fhist=load(f)
	f.close()
	
	pyopl.init()
	pyopl.close()
	
	f1=pyopl.figure()
	
	pyopl.lock(True)
	
	if pyopl.alive(f1):
		ax=f1.add_subplot(1,1,1)
		ax.semilogy(arange(len(fhist))/popsize, fhist)
		ax.set_xlabel('generation')
		ax.set_ylabel('f')
		ax.set_title('Progress of differential evolution')
		ax.grid()
		
	pyopl.lock(False)
	
	pyopl.join()
	
示例#14
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
示例#15
0
import pyopus.wxmplplot as pyopl

if __name__ == '__main__':
    # Initialize gui thread. The thread exits when control window is closed.
    pyopl.init()

    # If the GUI thread was running before init(),
    # there might be some plot windows around.
    # Close them.
    pyopl.close()

    # Create a figure with default size (matplotlibrc).
    f0 = pyopl.figure()
    print("pyopl.figure() returned: " + str(f0))

    # Create a figure with 400x300 pixels, 100dpi. This gives a 4x3 inch image.
    f1 = pyopl.figure(windowTitle="Window title 1", figpx=(400, 300), dpi=100)
    print("pyopl.figure() returned: " + str(f1))

    # Change window title.
    pyopl.title(f1, "Changed window title 2")

    # Close a figure.
    # pyopl.close(f1)

    # Close all figures
    # pyopl.close()

    # Show/hide (True/False) figure
    # pyopl.showFigure(f0, False)
    # pyopl.showFigure(f0, True)
示例#16
0
文件: an.py 项目: ustaros-ai/pyopus
    f.close()

    print summary

    findex = 0
    popsize = 10
    runindex = 0

    f = open("fhist_f%d_p%d_r%d.pck" % (findex, popsize, runindex), "rb")
    fhist = load(f)
    f.close()

    pyopl.init()
    pyopl.close()

    f1 = pyopl.figure()

    pyopl.lock(True)

    if pyopl.alive(f1):
        ax = f1.add_subplot(1, 1, 1)
        ax.semilogy(arange(len(fhist)) / popsize, fhist)
        ax.set_xlabel('generation')
        ax.set_ylabel('f')
        ax.set_title('Progress of differential evolution')
        ax.grid()

    pyopl.lock(False)

    pyopl.join()
示例#17
0
from numpy import arange, sin, cos, exp, pi, e, linspace, outer, ones, size

if __name__ == '__main__':
	# Initialize gui thread, clean up. 
	pyopl.init()
	pyopl.close()

	# Plot data - sin(x), cos(x), exp(x/pi) .. for x in [0, 2pi] with 0.2 step. 
	x = arange(0.0, 2*pi, 0.2)
	y1 = sin(x)
	y2 = cos(x)
	y3 = exp(x/pi)
	
	# Create first figure (plot window). This is now the active figure. 
	# Tag is assigned automatically by the system. 
	f1=pyopl.figure(windowTitle="Figure - single axes", figpx=(600,400), dpi=100)	
	
	# Lock the main GUI event loop. This implicitly disables repainting. 
	pyopl.lock(True)
	
	# If the window is closed the C++ part of the panel object is deleted, 
	# but the wxPython wrapper is still around. Accessing any attribute then 
	# results in an exception. To check if the C++ part is still there, call  
	# the alive() function with figure as argument. 
	if pyopl.alive(f1):
		ax = f1.add_subplot(1, 1, 1, projection='3d')

		u = linspace(0, 2 * pi, 100)
		v = linspace(0, pi, 100)

		x = 10 * outer(cos(u), sin(v))
示例#18
0
	# Round n to next greater or equal even number (nn)
	nn=int(np.ceil(n/2)*2)
	
	# Halton/Sobol sequence generator
	gen=ghalton.Halton(nn)
	# gen=sobol.Sobol(nn)
	
	# Skip first nn entries
	gen.get(nn)
	
	# Initialize gui thread, clean up.
	pyopl.init()
	pyopl.close()
	
	# Create first figure (plot window). This is now the active figure.
	f1=pyopl.figure(windowTitle="Random points inside a disc", figpx=(600,400), dpi=100)
	
	# Lock GUI
	pyopl.lock(True)
	
	# Check if figure is alive
	if pyopl.alive(f1):
		ax1=f1.add_axes((0.12,0.12,0.76,0.76))
		
		ax1.hold(True)

		ii=0
		rskips=0
		mskips=0
		while ii<150:
			# Get vector of length nn
示例#19
0
import pyopus.wxmplplot as pyopl
from numpy import arange, sin, cos, exp, pi, e

if __name__ == '__main__':
	# Initialize gui thread, clean up. 
	pyopl.init()
	pyopl.close()

	# Plot data - sin(x), cos(x), exp(x/pi) .. for x in [0, 2pi] with 0.2 step. 
	x = arange(0.0, 2*pi, 0.2)
	y1 = sin(x)
	y2 = cos(x)
	y3 = exp(x/pi)
	
	# Plot window
	f1=pyopl.figure(windowTitle="Scaling", figpx=(800,400), dpi=100)
	
	# Lock GUI
	pyopl.lock(True)
	
	# Check if figure is alive
	if pyopl.alive(f1):
		# Create 2 subplots, horizontal stack of 2
		ax1=f1.add_subplot(1,2,1)
		ax2=f1.add_subplot(1,2,2)
		
		# First axes
		ax1.hold(True)
		ax1.plot(x, y1, '-o', label='sin(x)', color=(1,0,0))
		ax1.plot(x, 2*y1, '-o', label='2sin(x)', color=(1,0,0))
		ax1.grid(True)