コード例 #1
0
    def update(self, settings, organisms, foods, gen, time):
        # CLEAR FIGURE
        self.ax.clear()
        self.setAxisLimits(settings)
        
        # PLOT ORGANISMS
        for organism in organisms:
            plot_organism(organism.x, organism.y, organism.r, self.ax)

        # PLOT FOOD PARTICLES
        for food in foods:
            plot_food(food.x, food.y, self.ax)

        # MISC PLOT SETTINGS
        self.ax.set_aspect('equal')
        frame = plt.gca()
        frame.axes.get_xaxis().set_ticks([])
        frame.axes.get_yaxis().set_ticks([])

        # ADD TEXT
        if self.texts[0] is None:
            self.texts[0] = self.fig.text(0.025, 0.95,r'GENERATION: '+str(gen))
        else:
            self.texts[0].set_text(r'GENERATION: '+str(gen))
            
        if self.texts[1] is None:
            self.texts[1] = self.fig.text(0.025, 0.90,r'T_STEP: '+str(time))
        else:
            self.texts[1].set_text(r'T_STEP: '+str(time))

        self.fig.canvas.draw()
        self.fig.canvas.flush_events()
コード例 #2
0
def plot_frame(settings, organisms, foods, gen, time):
    fig, ax = plt.subplots()
    fig.set_size_inches(9.6, 5.4)

    plt.xlim([
        settings['x_min'] + settings['x_min'] * 0.25,
        settings['x_max'] + settings['x_max'] * 0.25
    ])
    plt.ylim([
        settings['y_min'] + settings['y_min'] * 0.25,
        settings['y_max'] + settings['y_max'] * 0.25
    ])

    # PLOT ORGANISMS
    for organism in organisms:
        plot_organism(organism.x, organism.y, organism.r, ax)

    # PLOT FOOD PARTICLES
    for food in foods:
        plot_food(food.x, food.y, ax)

    # MISC PLOT SETTINGS
    ax.set_aspect('equal')
    frame = plt.gca()
    frame.axes.get_xaxis().set_ticks([])
    frame.axes.get_yaxis().set_ticks([])

    plt.figtext(0.025, 0.95, r'GENERATION: ' + str(gen))
    plt.figtext(0.025, 0.90, r'T_STEP: ' + str(time))

    plt.savefig(str(gen) + '-' + str(time) + '.png', dpi=100)
コード例 #3
0
def plot_frame(settings, folder, fig, ax, isings, foods, time, rep):
    # fig, ax = plt.subplots()
    fig.set_size_inches(9.6, 5.4)

    # plt.xlim([settings['x_min'] + settings['x_min'] * 0.25,
    #           settings['x_max'] + settings['x_max'] * 0.25])
    # plt.ylim([settings['y_min'] + settings['y_min'] * 0.25,
    #           settings['y_max'] + settings['y_max'] * 0.25])
    pad = 0.5

    plt.xlim([settings['x_min'] - pad, settings['x_max'] + pad])
    plt.ylim([settings['y_min'] - pad, settings['y_max'] + pad])

    # PLOT ORGANISMS
    for I in isings:
        plot_organism(settings, I.xpos, I.ypos, I.r, ax)

    # PLOT FOOD PARTICLES
    for food in foods:
        plot_food(settings, food.xpos, food.ypos, ax)

    # MISC PLOT SETTINGS
    ax.set_aspect('equal')
    frame = plt.gca()
    frame.axes.get_xaxis().set_ticks([])
    frame.axes.get_yaxis().set_ticks([])

    plt.figtext(0.025, 0.90, r'T_STEP: ' + str(time))

    # if settings['plotLive'] == True:
    #     plt.show()
    if settings['save_data'] == True:
        filename = folder + 'figs/iter-' + str(rep) + 'time-' + str(
            time).zfill(4) + '.png'
        plt.savefig(filename, dpi=300)