def plot_u(u, x, xv, y, yv, t, n): if t[n] == 0: time.sleep(2) if plot_method == 1: mesh(x, y, u, title='t=%g' % t[n], zlim=[-1,1], caxis=[-1,1]) elif plot_method == 2: easyviz.surfc(xv, yv, u, title='t=%g' % t[n], zlim=[-1, 1], colorbar=True, colormap=hot(), caxis=[-1,1], shading='flat') elif plot_method == 3: print 'Experimental 3D matplotlib...under development...' #plt.clf() ax = fig.add_subplot(111, projection='3d') u_surf = ax.plot_surface(xv, yv, u, alpha=0.3) #ax.contourf(xv, yv, u, zdir='z', offset=-100, cmap=cm.coolwarm) #ax.set_zlim(-1, 1) # Remove old surface before drawing if u_surf is not None: ax.collections.remove(u_surf) plt.draw() time.sleep(1) if plot_method > 0: time.sleep(0) # pause between frames if save_plot: filename = 'tmp_%04d.png' % n savefig(filename) # time consuming!
def display(self,tn,Ix,Iy,u_2,u_1,u): n = self.n plt = self.plt if n==0: plt.surfc(Ix,Iy,u_2[1:-1,1:-1], title='t=%g'%tn, zlim=[-1.2, 1.2], colorbar=True,caxis=[-1,1],shading='flat',view=[30,35]) elif n==1: plt.surfc(Ix,Iy,u_1[1:-1,1:-1], title='t=%g'%tn, zlim=[-1.2, 1.2], colorbar=True,caxis=[-1,1],shading='flat',view=[30,35]) else: plt.surfc(Ix,Iy,u[1:-1,1:-1], title='t=%g'%tn, zlim=[-1.2, 1.2], colorbar=True,caxis=[-1,1],shading='flat',view=[30,35]) self.n = n + 1
def store_fig(self,tn,Ix,Iy,u_2,u_1,u): n = self.n filename = self.filename destination = self.destination plt = self.plt if n==0: plt.surfc(Ix,Iy,u_2[1:-1,1:-1], title='t=%g'%tn, zlim=[-1.2, 1.2], colorbar=True,caxis=[-1,1],shading='flat',view=[30,35], hardcopy="%s/%s/%s_%04d.png"%(destination,filename,filename,n)) elif n==1: plt.surfc(Ix,Iy,u_1[1:-1,1:-1], title='t=%g'%tn, zlim=[-1.2, 1.2], colorbar=True,caxis=[-1,1],shading='flat',view=[30,35], hardcopy="%s/%s/%s_%04d.png"%(destination,filename,filename,n)) else: plt.surfc(Ix,Iy,u[1:-1,1:-1], title='t=%g'%tn, zlim=[-1.2, 1.2], colorbar=True,caxis=[-1,1],shading='flat',view=[30,35], hardcopy="%s/%s/%s_%04d.png"%(destination,filename,filename,n)) self.n = n + 1