import numpy as np from numpy import * import matplotlib matplotlib.use('TkAgg') from matplotlib import pyplot as plt from matplotlib import animation from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm import sys import os filename = sys.argv[1] print "Compiling " + filename + ".c..." bashCommand = "gcc " + filename + ".c -o " + filename + " -lm" os.system(bashCommand) print "Executing "+filename+".o..." bashCommand = "./"+filename os.system(bashCommand) datafile = "data.dat" print ("Importing data from " + datafile + "...") print ("Using comma delimiter") NX = 60 NY = 60 T = 40 # NZ = 40 # x,y = np.loadtxt(datafile, delimiter = ',') # uu = np.loadtxt('2d_data.dat')#.reshape(T,NX,NY) uu = np.loadtxt('data.dat')#.reshape(T,NX,NY) print(size(uu)) uu = uu.reshape(T,NX,NY) # uu = uu.reshape(NZ,NX,NY) # uu = np.genfromtxt('data.dat', delimiter=',')[:,:-1] # data = data.T print uu x, y = meshgrid(arange(NX),arange(NY)) # x, y = meshgrid(arange(NX),arange(T)) fig = plt.figure() ax = Axes3D(fig) # ax = plt.axes(xlim=(0,NX), ylim=(0,NY)) # wireframe = ax.plot_surface(x, y, uu[0,x,y], rstride=2, cstride=2,cmap=cm.hot) wireframe = ax.plot_wireframe(x, y, uu[0,x,y],color="black",rstride=1, cstride=1) # wireframe = ax.contourf(x, y, uu[0,x,y],1) ax.set_zlim(-0,0.05) # # animation function. This is called sequentially def animate(i, ax, fig): global x,y,uu ax.cla() # wireframe = ax.plot_surface(x, y, uu[i,x,y], rstride=2, cstride=2,cmap=cm.hot) wireframe = ax.plot_wireframe(x, y, uu[i,x,y],color="black",rstride=1, cstride=1) # wireframe = ax.plot_wireframe(x, y, uu[y,x,i],color="black",rstride=1, cstride=1) # wireframe = ax.contourf(x, y, uu[i,x,y],100) ax.set_zlim(-0.0,0.05) return wireframe, anim = animation.FuncAnimation(fig, animate, frames=T, fargs=(ax, fig), interval=5) # anim.save('2d_fdtd.gif', writer='imagemagick', fps=30) plt.show()