animate.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:visual_mpc 作者: febert 项目源码 文件源码
def build_figure(self):

        # plot each markevery case for linear x and y scales
        figsize = (10, 8)
        fig = plt.figure(num=1, figsize=figsize)
        axes_list = []

        num_rows = len(self.row_list)
        outer_grid = gridspec.GridSpec(num_rows, 1)
        for row in range(num_rows):
            # outer_ax = fig.add_subplot(outer_grid[row])
            # if self.row_list[row][1] != '':
            #     outer_ax.set_title(self.row_list[1])

            inner_grid = gridspec.GridSpecFromSubplotSpec(1, self.num_ex,
                              subplot_spec=outer_grid[row], wspace=0.0, hspace=0.0)

            image_row = self.row_list[row][0]

            for col in range(self.num_ex):
                ax = plt.Subplot(fig, inner_grid[col])
                ax.set_xticks([])
                ax.set_yticks([])
                axes_list.append(fig.add_subplot(ax))
                if row==0:
                    axes_list[-1].set_title('ex{}'.format(col))
                axes_list[-1].imshow(image_row[0][col], interpolation='none')

        plt.axis('off')
        fig.tight_layout()
        plt.show()

        # initialization function: plot the background of each frame

        # Set up formatting for the movie files
        Writer = animation.writers['imagemagick_file']
        writer = Writer(fps=15, metadata=dict(artist='Me'), bitrate=1800)

        # call the animator.  blit=True means only re-draw the parts that have changed.
        anim = animation.FuncAnimation(fig, self.animate, init_func=self.init,
                                       frames=13, interval=50, blit=True)
        anim.save('basic_animation.gif', writer='imagemagick')
        plt.show()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号