コード例 #1
0
    def draw():
        lineList = SimulatedAnnealingTSP.lineList
        linecollections = collections.LineCollection(lineList)
        fig = plt.gcf()
        fig.clf()
        fig.patch.set_facecolor("w")
        DPI = fig.get_dpi()
        fig.set_size_inches(800.0 / float(DPI), 600.0 / float(DPI))
        plt.axis('off')
        ax = fig.add_subplot(111)
        ax.add_collection(linecollections, autolim=True)

        for x in SimulatedAnnealingTSP.pointList:
            ax.scatter(x[0], x[1], s=10, c="#ff0000", alpha=0.8)
        totalLength = SimulatedAnnealingTSP.getTotalLength()
        desp_patch = mpatches.Patch(
            color='red',
            label="temperature:%f,length=%f" %
            (SimulatedAnnealingTSP.temperature, totalLength))
        # draw_Barnsley(ax)
        ax.legend(handles=[desp_patch])
        ax.axis("equal")
        ax.set_axis_off()
        ax.set_xlim(ax.dataLim.xmin, ax.dataLim.xmax)
        ax.invert_yaxis()
        fig.canvas.draw()
        _pybridge.PyRendererAggBufferRGBA(fig.canvas.get_renderer()._renderer)
        fig.clf()
コード例 #2
0
 def draw():
     lineList = []
     lineList.append(((10, 20), (110, 20)))
     lineList.append(((10, 40), (110, 40)))
     lineList.append(((10, 60), (110, 60)))
     lineList.append(((10, 80), (110, 80)))
     lineList.append(((10, 100), (110, 100)))
     lineList.append(((10, 120), (110, 120)))
     lineList.append(((10, 140), (110, 140)))
     lineList.append(((10, 160), (110, 160)))
     lineList.append(((10, 180), (110, 180)))
     lineList.append(((10, 200), (110, 200)))
     linecollections = collections.LineCollection(lineList)
     fig = plt.gcf()
     fig.clf()
     fig.patch.set_facecolor("w")
     DPI = fig.get_dpi()
     fig.set_size_inches(800.0 / float(DPI), 600.0 / float(DPI))
     plt.axis('off')
     ax = fig.add_subplot(111)
     ax.add_collection(linecollections, autolim=True)
     ypos = 20
     for x in Pendulum.posList:
         xpos = 60 + x
         ax.scatter(xpos, ypos, s=700, c=nm.random.rand(), alpha=0.5)
         ypos += 20
     ax.axis("equal")
     ax.set_axis_off()
     ax.set_xlim(ax.dataLim.xmin, ax.dataLim.xmax)
     ax.invert_yaxis()
     fig.canvas.draw()
     _pybridge.PyRendererAggBufferRGBA(fig.canvas.get_renderer()._renderer)
     fig.clf()
コード例 #3
0
    def draw():
        fig = plt.gcf()
        fig.clf()
        fig.patch.set_facecolor("w")
        DPI = fig.get_dpi()
        fig.set_size_inches(700.0 / float(DPI), 600.0 / float(DPI))
        plt.axis('off')
        ax = fig.add_subplot(121)
        ax.scatter(100, BouncingBall.pos + 3, s=700, c='#0000ff', alpha=0.8)
        ax2 = fig.add_subplot(122)

        if BouncingBall.drawParam == 'x':
            ax2.set_ylim(-10, 70)
            ax2.plot(BouncingBall.timeList, BouncingBall.posList)
            ax2.set_xlabel("t(s)")
            ax2.set_ylabel("pos(m)")
        else:
            ax2.plot(BouncingBall.timeList, BouncingBall.vList)
            ax2.set_xlabel("t(s)")
            ax2.set_ylabel("v(m/s)")
            ax2.set_xlim(ax2.dataLim.xmin, ax2.dataLim.xmax)
        ax.axis("equal")
        #ax.set_axis_off()
        ax.set_xlim(ax.dataLim.xmin, ax.dataLim.xmax)
        ax.set_ylim(0, 80)
        #ax.invert_yaxis()
        fig.canvas.draw()
        _pybridge.PyRendererAggBufferRGBA(fig.canvas.get_renderer()._renderer)
        fig.clf()
コード例 #4
0
ファイル: load.py プロジェクト: saturnman/mm-pages
 def drawFibu():
     r = nm.arange(2.501, 3.8, 0.001)
     s = nm.random.random_sample(r.shape)
     x = ChaosModel.calc_stable_x(s, r)
     points = []
     for i in range(len(x)):
         for j in range(len(x[i])):
             points.append((r[j], x[i][j]))
     (x1, y1) = zip(*points)
     fig = plt.gcf()
     plt.clf()
     plt.axis('off')
     DPI = fig.get_dpi()
     fig.set_size_inches(1200.0 / float(DPI), 800.0 / float(DPI))
     #fig = plt.figure()
     plt.scatter(x1, y1, marker='.', lw=0, color="r", s=1)
     #print dir(fig.canvas.get_renderer())
     #print fig.canvas.get_renderer()
     #print fig.canvas.get_renderer().height
     #print dir(fig._cachedRenderer)
     #print fig.canvas.get_renderer().get_content_extents()
     #print fig.canvas.get_renderer()
     #print fig.canvas.renderer._renderer
     #fig.savefig('fibu.png', dpi=fig.dpi)
     plt.axis('on')
     fig.canvas.draw()
     _pybridge.PyRendererAggBufferRGBA(fig.canvas.renderer._renderer)
     fig.clf()
コード例 #5
0
ファイル: load.py プロジェクト: saturnman/mm-pages
    def draw():
        fig = plt.gcf()
        #SIZE = lena.shape[0]
        #注意:此参数会极大影响计算过程的内存消耗,对于小内存机器可以会让计算进程因内存不够而出错,请自行调节计算

        #x_min, x_max = -2.5, 1
        #y_min, y_max = -1.2, 1.2
        #x,y = nm.meshgrid(nm.linspace(x_min,x_max,2*Julia.SIZE),nm.linspace(y_min,y_max,Julia.SIZE));
        #c = x + 1j*y
        #z = c.copy()
        #fractal = nm.zeros(z.shape,dtype=nm.uint8)+Julia.MAX_COLOR
        #for n in range(Julia.ITERATIONS):
        #    mask = nm.abs(z) <=10
        #    z[mask] = z[mask]**2+c[mask]
        #    fractal[(fractal==Julia.MAX_COLOR) & (~mask)] = (Julia.MAX_COLOR-1)*n/ITERATIONS
        # Display the fractal
        DPI = fig.get_dpi()
        fig.set_size_inches(1500.0 / float(DPI), 800.0 / float(DPI))
        #print Julia.fractal
        im = plt.imshow(Julia.fractal, cmap=plt.get_cmap('flag'))
        #plt.title('Mandelbrot')
        plt.axis('off')
        im.figure.canvas.draw()
        _pybridge.PyRendererAggBufferRGBA(
            im.figure.canvas.get_renderer()._renderer)
        fig.clf()
コード例 #6
0
def Buffon_draw(data):
    fig = pl.gcf()
    fig.patch.set_facecolor("w")
    DPI = fig.get_dpi()
    fig.set_size_inches(1200.0 / float(DPI), 800.0 / float(DPI))

    #for i in xrange(6):
    #    ax = fig.add_subplot(241+i)
    #    draw(ax, rules[i])
    #ax = fig.add_subplot(247)
    #draw_Barnsley(ax)
    #fig.add_subplot(247)
    pl.axis('off')
    ax = fig.add_subplot(121)
    draw(ax)
    ax2 = fig.add_subplot(122)
    ax2.plot(Buffon.numNeedleList, Buffon.piEstimationValList)
    ax2.set_axis_on()
    desp_patch = mpatches.Patch(
        color='red',
        label="n needls:%d,pi=%f" %
        (Buffon.numNeedle, Buffon.piEstimationValList[-1]))
    #draw_Barnsley(ax)
    ax2.legend(handles=[desp_patch])
    fig.subplots_adjust(left=0, right=1, bottom=0, top=1, wspace=0, hspace=0)
    #pl.show()
    fig.canvas.draw()
    _pybridge.PyRendererAggBufferRGBA(fig.canvas.get_renderer()._renderer)
    fig.clf()
コード例 #7
0
ファイル: load.py プロジェクト: saturnman/mm-pages
    def draw():
        fig = plt.gcf()
        fig.clf()
        fig.patch.set_facecolor("w")
        DPI = fig.get_dpi()
        fig.set_size_inches(800.0/float(DPI),600.0/float(DPI))
        #plt.axis('off')
        ax = fig.add_subplot(111)
        a, b, m, n = 1, 0.8, 1, 0.5
        X, Y = meshgrid(arange(-0.1, 4, .3), arange(-0.1, 4, .3))
        U = a * X - b * X * Y
        V = -m * Y + n * X * Y
        Q = ax.quiver(U, V)
        l, r, b, t = axis()
        dx, dy = r - l, t - b
        ax.scatter(PredatorPrey.x, PredatorPrey.y, s=10, c="#ff0000", alpha=0.8)


        desp_patch = mpatches.Patch(color='red',
                                    label="x:%f,y=%f" % (PredatorPrey.x,PredatorPrey.y))
        # draw_Barnsley(ax)
        ax.legend(handles=[desp_patch])
        ax.axis("equal")
        #ax.set_axis_off()
        ax.set_xlim(ax.dataLim.xmin, ax.dataLim.xmax)
        fig.canvas.draw()
        _pybridge.PyRendererAggBufferRGBA(fig.canvas.get_renderer()._renderer)
        fig.clf()
コード例 #8
0
def LSystem_draw_Barnsley(data):
    params = data['params']
    paramsMatrix = numpy.asarray(params)
    slim = data['slim']

    fig = pl.gcf()
    fig.patch.set_facecolor("w")
    DPI = fig.get_dpi()
    if slim:
        fig.set_size_inches(300.0 / float(DPI), 600.0 / float(DPI))
    else:
        fig.set_size_inches(1000.0/float(DPI),600.0/float(DPI))

    #for i in xrange(6):
    #    ax = fig.add_subplot(241+i)
    #    draw(ax, rules[i])
    #ax = fig.add_subplot(247)
    #draw_Barnsley(ax)
    #fig.add_subplot(247)
    pl.axis('off')
    ax = fig.add_subplot(111)
    #draw(ax,rules[rule])
    draw_Barnsley(ax,paramsMatrix)
    fig.subplots_adjust(left=0,right=1,bottom=0,top=1,wspace=0,hspace=0)
    #pl.show()
    fig.canvas.draw()
    _pybridge.PyRendererAggBufferRGBA(fig.canvas.get_renderer()._renderer)
    fig.clf()
コード例 #9
0
ファイル: load.py プロジェクト: saturnman/mm-pages
    def draw():
        lineList = GeneticTSP.lineList
        linecollections = collections.LineCollection(lineList)
        fig = plt.gcf()
        fig.clf()
        fig.patch.set_facecolor("w")
        gs = gridspec.GridSpec(1, 2, width_ratios=[2, 4])
        DPI = fig.get_dpi()
        fig.set_size_inches(GeneticTSP.width / float(DPI),
                            GeneticTSP.height / float(DPI))
        plt.axis('off')
        plt.tight_layout(pad=0)
        #ax = fig.add_subplot(111)
        ax1 = plt.subplot(gs[0])
        top5AgentList = []
        for i in range(5):
            citySeq = GeneticTSP.agentList[i].citySequence
            citySeqFix = []
            zeroIndex = citySeq.index(0)
            for _ in range(GeneticTSP.numPoints):
                citySeqFix.append(citySeq[zeroIndex])
                zeroIndex = (zeroIndex + 1) % GeneticTSP.numPoints
            top5AgentList.append(citySeqFix)
        top5AgentArray = nm.array(top5AgentList)
        top5AgentArray = nm.transpose(top5AgentArray)

        table = ax1.table(cellText=top5AgentArray,
                          cellLoc='center',
                          bbox=[0, 0, 1, 1])
        table.set_fontsize(18)

        if GeneticTSP.top5AgentArray is None:
            GeneticTSP.top5AgentArray = top5AgentArray
        else:
            for key, c in table.get_celld().iteritems():
                if GeneticTSP.top5AgentArray[key] != top5AgentArray[key]:
                    c.set(facecolor='#00ff00')
                if key[0] == 0:
                    c.set(facecolor='#ff0000')
            GeneticTSP.top5AgentArray = top5AgentArray
        ax1.set_axis_off()
        ax = plt.subplot(gs[1])
        ax.add_collection(linecollections, autolim=True)

        for x in GeneticTSP.pointList:
            ax.scatter(x[0], x[1], s=10, c="#ff0000", alpha=0.8)
        totalLength = GeneticTSP.getTotalLength()
        desp_patch = mpatches.Patch(color='red',
                                    label="generation:%d,length=%f" %
                                    (GeneticTSP.generation, totalLength))
        # draw_Barnsley(ax)
        ax.legend(handles=[desp_patch])
        ax.axis("equal")
        ax.set_axis_off()
        ax.set_xlim(ax.dataLim.xmin, ax.dataLim.xmax)
        ax.invert_yaxis()
        fig.canvas.draw()
        _pybridge.PyRendererAggBufferRGBA(fig.canvas.get_renderer()._renderer)
        fig.clf()
コード例 #10
0
    def drawLogisticPopulationModel(r, x1start, x2start, iter_count, lines=1):
        def calculate_trajectory(seed, r, count):
            result = []
            x = seed
            f = lambda r, x: r * x * (1 - x)
            for i in range(0, count):
                x = f(r, x)
                result.append(x)
            return result

        if lines == 1:
            x = range(0, iter_count)
            y1 = calculate_trajectory(0.2, r, iter_count)
            fig = plt.gcf()
            fig.set_size_inches(18.5, 10.5)
            labelText = "seed=" + str(x1start) + ",r=" + str(
                r) + ",steps=" + str(iter_count)
            plot1 = plt.plot(x, y1, color="r", label=labelText)
            plt.xlabel("steps")
            plt.ylabel("iterated value")
            fig.canvas.draw()
            _pybridge.PyRendererAggBufferRGBA(
                fig.canvas.get_renderer()._renderer)
            fig.clf()
        elif lines == 2:
            x = range(0, iter_count)
            y1 = calculate_trajectory(x1start, r, iter_count)
            y2 = calculate_trajectory(x2start, r, iter_count)
            fig = plt.gcf()
            fig.set_size_inches(18.5, 10.5)
            label1Text = "seed=" + str(x1start) + ",r=" + str(
                r) + ",steps=" + str(iter_count)
            label2Text = "seed=" + str(x2start) + ",r=" + str(
                r) + ",steps=" + str(iter_count)
            plot1 = plt.plot(x, y1, color="r", label=label1Text)
            plot2 = plt.plot(x, y2, color="b", label=label2Text)
            plt.xlabel("steps")
            plt.ylabel("iterated value")
            fig.canvas.draw()
            _pybridge.PyRendererAggBufferRGBA(
                fig.canvas.get_renderer()._renderer)
            fig.clf()
        else:
            print 'illegal param'
コード例 #11
0
ファイル: load.py プロジェクト: saturnman/mm-pages
 def draw():
     fig = plt.gcf()
     fig.clf()
     griddata = 1-GameOfLife.gridData
     plt.grid(which='none', axis='none', linestyle='-', color='r')
     im = plt.imshow(griddata, cmap=plt.cm.gray, interpolation='nearest',vmin=0,vmax=1)
     #matplotlib.pyplot.axis('off')
     DPI = fig.get_dpi()
     fig.set_size_inches(1000.0 / float(DPI), 468.0 / float(DPI))
     fig.canvas.draw()
     _pybridge.PyRendererAggBufferRGBA(im.figure.canvas.get_renderer()._renderer)
     fig.clf()
コード例 #12
0
ファイル: load.py プロジェクト: saturnman/mm-pages
 def draw():
     fig = plt.gcf()
     fig.clf()
     fig.subplots_adjust(top=0.8, bottom=0.05, left=0.01, right=0.99)
     gs = gridspec.GridSpec(1, 2, width_ratios=[4, 1])
     x = nm.arange(0, 10, 0.2)
     y = nm.sin(x)
     ax0 = plt.subplot(gs[0])
     ax1 = plt.subplot(gs[1])
     griddata = SpatialGame.gridData
     print griddata[(0, 0)]
     plt.grid(which='none', axis='none', linestyle='-', color='r')
     im = ax0.imshow(griddata,
                     cmap=plt.cm.get_cmap('indexed'),
                     interpolation="nearest",
                     vmin=0,
                     vmax=4)
     ax1.scatter(20, 20, s=700, c='#0000ff', alpha=1.0)
     ax1.annotate('CC',
                  xy=(20, 20),
                  xycoords='data',
                  xytext=(20, 20),
                  textcoords='offset points',
                  arrowprops=dict(arrowstyle="->"))
     ax1.scatter(20, 40, s=700, c='#ff0000', alpha=1.0)
     ax1.annotate('DD',
                  xy=(20, 40),
                  xycoords='data',
                  xytext=(20, 40),
                  textcoords='offset points',
                  arrowprops=dict(arrowstyle="->"))
     ax1.scatter(20, 60, s=700, c='#00ff00', alpha=1.0)
     ax1.annotate('DC',
                  xy=(20, 60),
                  xycoords='data',
                  xytext=(20, 60),
                  textcoords='offset points',
                  arrowprops=dict(arrowstyle="->"))
     ax1.scatter(20, 80, s=700, c='#ffff00', alpha=1.0)
     ax1.annotate('CD',
                  xy=(20, 80),
                  xycoords='data',
                  xytext=(20, 80),
                  textcoords='offset points',
                  arrowprops=dict(arrowstyle="->"))
     matplotlib.pyplot.axis('off')
     DPI = fig.get_dpi()
     fig.set_size_inches(1200.0 / float(DPI), 1000.0 / float(DPI))
     fig.canvas.draw()
     _pybridge.PyRendererAggBufferRGBA(
         im.figure.canvas.get_renderer()._renderer)
     fig.clf()
コード例 #13
0
    def draw(self):

        # set point-of-view: specified by (altitude degrees, azimuth degrees)
        self.ax.view_init(30, 0.3 * self.steps)
        for line, pt, xi in zip(self.lines, self.pts, self.x_t):
            x, y, z = xi[:self.steps].T
            line.set_data(x, y)
            line.set_3d_properties(z)

            pt.set_data(x[-1:], y[-1:])
            pt.set_3d_properties(z[-1:])

        self.fig.canvas.draw()
        _pybridge.PyRendererAggBufferRGBA(self.fig.canvas.get_renderer()._renderer)
コード例 #14
0
def LSystem_draw_Barnsley(data):
    rule = data['rule']
    fig = pl.gcf()
    fig.patch.set_facecolor("w")
    DPI = fig.get_dpi()
    fig.set_size_inches(1200.0 / float(DPI), 800.0 / float(DPI))

    #for i in xrange(6):
    #    ax = fig.add_subplot(241+i)
    #    draw(ax, rules[i])
    #ax = fig.add_subplot(247)
    #draw_Barnsley(ax)
    #fig.add_subplot(247)
    pl.axis('off')
    ax = fig.add_subplot(111)
    draw(ax, rules[rule])
    #draw_Barnsley(ax)
    fig.subplots_adjust(left=0, right=1, bottom=0, top=1, wspace=0, hspace=0)
    #pl.show()
    fig.canvas.draw()
    _pybridge.PyRendererAggBufferRGBA(fig.canvas.get_renderer()._renderer)
    fig.clf()
コード例 #15
0
ファイル: load.py プロジェクト: saturnman/mm-pages
    def draw(self):
        # Set up figure & 3D axis for animation
        self.fig = plt.gcf()
        self.fig.patch.set_facecolor("w")
        DPI = self.fig.get_dpi()
        self.fig.set_size_inches(1200.0 / float(DPI), 1200.0 / float(DPI))

        self.ax = self.fig.add_axes([0, 0, 1, 1], projection='3d')
        self.ax.axis('off')
        self.ax.axis("equal")
        self.ax.set_axis_off()
        # choose a different color for each trajectory
        self.colors = plt.cm.jet(np.linspace(0, 1, self.N_trajectories))

        # set up lines and points
        self.lines = sum(
            [self.ax.plot([], [], [], '-', c=c) for c in self.colors], [])
        self.pts = sum(
            [self.ax.plot([], [], [], 'o', c=c) for c in self.colors], [])

        # prepare the axes limits
        self.ax.set_xlim((-30, 30))
        self.ax.set_ylim((-35, 35))
        self.ax.set_zlim((0, 60))

        # set point-of-view: specified by (altitude degrees, azimuth degrees)
        self.ax.view_init(30, 0.3 * self.steps)
        for line, pt, xi in zip(self.lines, self.pts, self.x_t):
            x, y, z = xi[:self.steps].T
            line.set_data(x, y)
            line.set_3d_properties(z)

            pt.set_data(x[-1:], y[-1:])
            pt.set_3d_properties(z[-1:])

        self.fig.canvas.draw()
        _pybridge.PyRendererAggBufferRGBA(
            self.fig.canvas.get_renderer()._renderer)
        self.fig.clf()
コード例 #16
0
    def draw():
        lineList = AntColonyTSP.lineList
        linecollections = collections.LineCollection(lineList,
                                                     linewidths=1,
                                                     colors="#FF0000")
        fig = plt.gcf()
        fig.clf()
        fig.patch.set_facecolor("w")
        DPI = fig.get_dpi()
        fig.set_size_inches(AntColonyTSP.width / float(DPI),
                            AntColonyTSP.height / float(DPI))
        plt.axis('off')
        plt.tight_layout(pad=0)
        ax = fig.add_subplot(111)

        #pheromoneList = AntColonyTSP.getPheromoneDensityLineList()
        res = AntColonyTSP.getPheromoneDensityLineList()
        p_lineList = res['lineList']
        p_colorList = res['colorList']
        #for l in pheromoneList:
        #    ax.add_line(l)
        p_collection = collections.LineCollection(p_lineList,
                                                  colors=p_colorList)
        ax.add_collection(p_collection, autolim=True)
        ax.add_collection(linecollections, autolim=True)
        for x in AntColonyTSP.pointList:
            ax.scatter(x[0], x[1], s=30, c="#FF00FF", alpha=1.0)
        totalLength = AntColonyTSP.getTotalLength()
        desp_patch = mpatches.Patch(color='red',
                                    label="length=%f" % (totalLength))
        # draw_Barnsley(ax)
        ax.legend(handles=[desp_patch])
        ax.axis("equal")
        ax.set_axis_off()
        ax.set_xlim(ax.dataLim.xmin, ax.dataLim.xmax)
        ax.invert_yaxis()
        fig.canvas.draw()
        _pybridge.PyRendererAggBufferRGBA(fig.canvas.get_renderer()._renderer)
        fig.clf()