Example #1
0
    def video(mesh, var, function, figsize=(10, 8), colorbar=True, skip=1):
        """
        Call a function for a list of models to create a video.

        ::

            def function(var, ax, clim, tlt, i):
                tlt.set_text('%d'%i)
                return mesh.plotImage(var, imageType='CC', ax=ax, clim=clim)

            mesh.video([model1, model2, ..., modeln],function)
        """
        # First set up the figure, the axis, and the plot element we want to animate
        fig = plt.figure(figsize=figsize)
        ax = plt.axes()
        VAR = np.concatenate(var)
        clim = [VAR.min(),VAR.max()]
        tlt = plt.title('')
        if colorbar:
            plt.colorbar(function(var[0],ax,clim,tlt,0))

        frames = np.arange(0,len(var),skip)
        def animateFrame(j):
            i = frames[j]
            function(var[i],ax,clim,tlt,i)

        return animate(fig, animateFrame, frames=len(frames))
Example #2
0
    def videoSlicer(mesh,var,imageType='CC',normal='z',figsize=(10,8)):
        assert mesh.dim > 2, 'This is for 3D meshes only.'
        # First set up the figure, the axis, and the plot element we want to animate
        fig = plt.figure(figsize=figsize)
        ax = plt.axes()
        clim = [var.min(),var.max()]
        plt.colorbar(mesh.slicer(var, imageType=imageType, normal=normal, index=0, ax=ax, clim=clim))
        tlt = plt.title(normal)

        def animateFrame(i):
            mesh.slicer(var, imageType=imageType, normal=normal, index=i, ax=ax, clim=clim)
            tlt.set_text(normal.upper()+('-Slice: %d, %4.4f' % (i,getattr(mesh,'vectorCC'+normal)[i])))

        return animate(fig, animateFrame, frames=mesh.vnC['xyz'.index(normal)])