コード例 #1
0
ファイル: coevolution.py プロジェクト: neffmallon/pistol
def coevolution(n=200,nsteps=6000):
    fitness = [random() for i in range(n)]
    least_fit_sites = []

    for step in range(nsteps):
        # Determine the least fit site
        worst = fitness.index(min(fitness))
        left = (worst-1)%n
        right = (worst+1)%n
        # Add that site to the least_fit_sites list
        least_fit_sites.append(worst)
        # Reinitialize the site and its neighbors
        fitness[worst] = random()
        fitness[left] = random()
        fitness[right] = random()

    # Plot how the least fit site changes with time
    p = Gnuplot()
    p.title("Coevolution data for %d steps with %d species" % (nsteps,n))
    p.xlabel("Step")
    d = Data(range(nsteps),least_fit_sites)
    p.plot(d)
    raw_input("press any key to continue")

    # Plot the frequency of the sites in the least_fit_site list:
    p2 = Gnuplot()
    p2.title("Frequency of least fit site")
    d2 = Data(range(n),frequency(n,least_fit_sites))
    p2.plot(d2)
    return
コード例 #2
0
ファイル: Pi.py プロジェクト: neffmallon/pistol
def plot_pi_gnuplot(npts=100):
    from Gnuplot import Gnuplot,Data
    g = Gnuplot()
    g.title("Pi computed using different approximations")
    g("set yrange [2:4]")
    steps = range(npts)
    data = []
    for func in sequences:
        data.append(Data(steps,func(npts),with='lines',title=func.__name__))
    apply(g.plot,data)
    return
コード例 #3
0
ファイル: Plot.py プロジェクト: bionomicron/Redirector
class Plot:
        
    def __init__(self):
        self.verbose = True
        self.origin = (0,0)
        self.data2 = []
        self.data3 = []
        self.g = Gnuplot()
        self.g('set data style points')
        self.g('set key left top Left title \'Legend\' box 3')
        self.title = 'title'
        self.xlabel = 'x'
        self.ylabel = 'y'
        self.zlabel = 'z'
        
    def __call__(self,value):
        self.g(value)
        
    def setOrigin(self,x,y):
        """
        @type x: float
        @type y: float
        """
        self.origin = (x,y)
        
    def setVerbose(self,verbose):
        """
        @type verbose: binary
        """
        self.verbose = verbose
        
    def addArrayTuples(self, data, name = ''):
        """
        @param data: data to be added to 2d plot
        @type data: (float,float)[]
        """
        d = Data(data, title = name)
        self.data2.append(d)
 
         
    def add2Arrays(self,x,y):
        """
        @type x: float[]
        @type y: float[]
        """
        if len(x) != len(y):
            return 'arrays not of equal length'
        else:
            array2 = []
            for i in range(len(array)):
                value = (x[i],y[i])
                array2.append(value)
            self.addArrayTuples(array2)
            
    def addArrayTriples(self, data):
        """
        @param data: data to be added to 3d plot
        @type data: (float, float, float)[]
        """        
        self.data3.append(data)
                  
    def add3Arrays(self,x,y,z):
        """
        @type x: float[]
        @type y: float[]
        @type z: float[]
        """        
        if (len(x) == len(y) == len(z)):
            array3 = []
            for i in range(len(x)):
                value = (x[i],y[i],z[i])
                array3.append(value)
            self.addArrayTriples(array3)
            
        else:
           print 'arrays not of equal length'
            
    def setLabels(self,title='title',xlabel='x',ylabel='y',zlabel='z'):
        """
        @type title: string
        @type xlabel: string
        @type ylable: string
        @type zlable: string
        """
        self.title = title
        self.xlabel = xlabel
        self.ylabel = ylabel
        self.zlabel = zlabel
        
    def _plot2D(self):
        self.g.title(self.title)
        self.g.xlabel(self.xlabel)
        self.g.ylabel(self.ylabel)
        if len(self.data2) == 0:
            return False
        self.g.title(self.title)
        self.g.xlabel(self.xlabel)
        self.g.ylabel(self.ylabel)
        self.g.plot(self.data2[0])
        for d in self.data2[1:]:
            self.g.replot(d)
        return True
    
    def plot2DtoScreen(self):
        if not self._plot2D():
            return None
        raw_input('Please press return to continue...\n')
    
    def plot2DtoFile(self, fileName):
        """
        @type fileName: string
        """
        self.g('set term post eps')
        self.g('set output \'%s\'' % fileName)
        if not self._plot2D():
            return None
        self.g.hardcopy(fileName, enhanced=1, color=1)
        if self.verbose: print ('\n******** Saved plot to postscript file %s ********\n' % fileName)
         
    def _plot3d(self):
        if len(self.data3) == 0:
            return False
        self.g.title(self.title)
        self.g.xlabel(self.xlabel)
        self.g.ylabel(self.ylabel)
        self.g('set zlabel \"%s\"' % self.zlabel)
        self.g.plot([self.data3[0]])
        for d in self.data3[1:]:
            self.g.replot(d)
        return True
    
    def plot3DtoScreen(self):
        if not self._plot3D():
            return None  
        raw_input('Please press return to continue...\n')
        
    def plot3DtoFile(self,fileName):
        """
        @type fileName: string
        """
        self.g('set term post eps')
        self.g('set output \'%s\'' % fileName)
        if not self._plot3d():
            return None
        self.g.hardcopy(fileName, enhanced=1, color=1)
        if self.verbose: print ('\n******** Saved plot to postscript file %s ********\n' % fileName)