Ejemplo n.º 1
0
def multi_frame(world, n_seq, **options):
    """Draw three timesteps.
    
    world: object with step, loop, and draw
    n_seq: 3-tuple, number of steps before each draw
    """
    m, n = world.array.shape
    options = underride(options,
                        cmap='Greens',
                        alpha=0.7,
                        vmin=0,
                        vmax=1,
                        interpolation='none',
                        origin='upper',
                        extent=[0, m, 0, n])

    count = len(n_seq)
    rows = ceil(count // 3)

    fig, axs = plt.subplots(rows, 3)
    # fig.set_size_inches
    counter = 0
    for i in range(rows):
        for j in range(3):
            axs[i, j].set_xticks([])
            axs[i, j].set_yticks([])
            if counter < count:
                world.loop(n_seq[counter])
                axs[i, j].imshow(world.array, **options)
                counter += 1

    plt.tight_layout()
    fig = plt.gcf()
    return fig
Ejemplo n.º 2
0
 def draw(self, **options):
     """Draw Sugarscape environment and agents."""
     options = underride(options,
                         cmap='YlOrRd',
                         vmax=9, origin='lower')
     self.init_fig(**options)
     self.im.set_data(self.array)
     return self.fig
Ejemplo n.º 3
0
    def init_fig(self, **options):
        """Initialize Sugarscape figure for animation and drawing."""
        options = underride(options,
                            cmap='YlOrRd',
                            vmax=9, origin='lower')
        self.fig, self.ax = plt.subplots()
        self.im = self.ax.imshow(self.array, **options)

        # draw the agents
        xs, ys = self.get_coords()
        self.points = self.ax.plot(xs, ys, '.', color='red')[0]
Ejemplo n.º 4
0
    def init_fig(self, **options):
        m, n = self.array.shape
        options = underride(options,
                            cmap='Greens',
                            alpha=0.7,
                            vmin=0, vmax=1,
                            interpolation='none',
                            origin='upper',
                            extent=[0, n, 0, m])

        self.fig, self.ax = plt.subplots()
        self.im = self.ax.imshow(self.array, **options)
Ejemplo n.º 5
0
    def init_fig(self, **options):
        """Initialize figure for animation and drawing."""
        options = underride(options,
                            cmap='Greens',
                            alpha=0.7,
                            vmin=0,
                            vmax=1,
                            interpolation='none',
                            origin='lower',
                            extent=[0, self.n, 0, self.m])

        self.fig, self.ax = plt.subplots()
        self.im = self.ax.imshow(self.array, **options)
        row, col = self.location
        self.line, = self.ax.plot(col + 0.5, row + 0.5, 'r.')
Ejemplo n.º 6
0
def draw_array(array, **options):
    """Draws the cells."""
    n, m = array.shape
    options = underride(options,
                        cmap='Greens',
                        alpha=0.7,
                        vmin=0, vmax=1,
                        interpolation='none',
                        origin='upper',
                        extent=[0, m, 0, n])

    plt.axis([0, m, 0, n])
    plt.xticks([])
    plt.yticks([])

    return plt.imshow(array, **options)
Ejemplo n.º 7
0
    def animate(self):

        # Set options for both images
        options = dict(interpolation='bicubic',
                        vmin=None, vmax=None,
                        cmap='Reds',
                        origin='lower')

        # Set specific options for im2
        options2 = underride(dict(cmap='Blues'), **options)

        # Initialize fig and make im
        self.init_fig(**options)

        # Make im2
        self.im2 = self.ax.imshow(self.array2, **options2)

        ani = FuncAnimation(self.fig, self.__class__.update_anim, fargs=(self,),
                interval=20)
        return ani
Ejemplo n.º 8
0
    def draw(self):
        #Set options for both images
        options = dict(interpolation='bicubic',
                        vmin=None, vmax=None,
                        cmap='Reds',
                        origin='lower')

        # Set specific options for im2
        options2 = underride(dict(cmap='Blues'), **options)

        # Initialize figure
        self.init_fig(**options)

        # Add a second imshow to axes
        self.im2 = self.ax.imshow(self.array2, **options2)

        # Set data for both images
        self.im.set_data(self.array)
        self.im2.set_data(self.array2)

        return self.fig
Ejemplo n.º 9
0
def draw_array(array, size=None, **options):
    """ Отрисовка матрицы """
    n, m = array.shape

    # параметры, неопределенные в словаре optopns доопределяются:
    options = underride(options,
                        cmap='Greens',
                        alpha=0.7,
                        vmin=0,
                        vmax=1,
                        interpolation='none',
                        origin='upper',
                        extent=[0, m, 0, n])

    plt.axis([0, m, 0, n])
    plt.xticks([])  # убираем
    plt.yticks([])  # деления
    fig = plt.gcf()
    if size is not None:
        fig.set_size_inches(size, size)
    plt.imshow(array, **options)

    return fig
Ejemplo n.º 10
0
 def animate(self, **options):
     options = underride(options, cmap='YlOrRd', vmax=5)
     ani = Cell2D.animate(self, **options)
     return ani
Ejemplo n.º 11
0
 def draw(self, **options):
     options = underride(options, cmap='YlOrRd', vmax=5)
     self.fig = Cell2D.draw(self, **options)
     return self.fig