def do(self, callback_name, *args):
        batch_size = self.N * self.N

        epochstr = ""
        if self.main_loop:
            epochstr = "-{:03d}".format(self.main_loop.log.status['epochs_done'])

        res = self.sample()
        outputs = res[-2]

        mins = []
        maxs = []
        for i in range(batch_size):
            points = outputs[:,i,:]
            xys = np.vstack((np.zeros((1,2)),np.cumsum(points[:,:2],axis=0)))
            xys[:,:2] -= xys[:,:2].mean(axis=0)
            mins.append(xys.min(axis=0))
            maxs.append(xys.max(axis=0))
        xmin, ymin = np.array(mins).min(axis=0)
        xmax, ymax = np.array(maxs).max(axis=0)

        # find a new grid of subplot which best match the y/x ratio
        r = (ymax-ymin)/(xmax-xmin)
        reverse = r > 1.
        if reverse: r = 1./r
        bestapprox = 10
        for f in range(1,self.N):
            if self.N % f != 0:
                continue
            rapprox = 1./float(f*f)
            if abs(r-rapprox) < abs(r-bestapprox):
                bestapprox = rapprox
                bestf = f

        if reverse:
            h, w = self.N//bestf, self.N*bestf
            r = 1./r
            bestapprox = 1./bestapprox
        else:
            h, w = self.N*bestf, self.N//bestf

        if bestapprox > r:
            newydelta = (ymax-ymin)*bestapprox/r
            ymax += newydelta/2.
            ymin -= newydelta/2.
        else:
            newxdelta = (xmax-xmin)*bestapprox/r
            xmax += newxdelta/2.
            xmin -= newxdelta/2.

        pl.close('all')
        fig = pl.figure('Sample sketches')
        fig.set_size_inches(25,25)
        for i in range(batch_size):
            pl.subplot(h,w,i+1)
            drawpoints(outputs[:,i,:], xmin, ymin, xmax, ymax)
        fname = os.path.join(self.path,'sketch{}.png'.format(epochstr))
        print('Writting to %s'%fname)
        pl.subplots_adjust(left=0.005,right=0.995,bottom=0.005,top=0.995,
                           wspace=0.01,hspace=0.01)
        pl.savefig(fname)

        fig = pl.figure('Pen down')
        fig.set_size_inches(17.5,17.5)
        img = 1-outputs[:,:,2]
        pl.imshow(img,cmap=cm.gray)
        pl.gca().set_xticks([])
        pl.gca().set_yticks([])
        pl.xlabel('iteration')
        pl.ylabel('sample')
        pl.title('Pen down for different samples vs. iteration step')
        if not os.path.exists(self.path):
            os.mkdir(self.path)
        fname = os.path.join(self.path,'pen{}.png'.format(epochstr))
        print('Writting to %s'%fname)
        pl.savefig(fname)


#----------------------------------------------------------------------------
dataset/ETHPy150Open udibr/sketch/sketch.py/Sample.do/swapped operands of `/`