python - To obtain the correct orientation of the contour plot and save the plots as seperate images when created in a loop? -
i have written code uses griddata interpolation interpolate points on irregular grid onto regular grid. creating contour plots 2 dependent variables after interpolation. able generate line contour , filled contour plots , match images qualitatively directly generated simulation. images shown in horizontal orientation , quality not per expectation. want images shown vertical i.e (x-axis; width =30.48(always fixed),y-axis; width varies according condition). in plots x , y interchanged. did not understand reason this. think has how rows , columns handled contour function.
my second issue importing multiple text files , want save generated contour plots separately each of imported text files. not sure of best way this.
from __future__ import print_function import numpy np matplotlib import pyplot plt scipy.interpolate import griddata ############################################################################### path = 'location of files' ft_init = 5.4311 delt = 0.15 ts_init = 140 dj_length = 2.4384 ############################################################################### def streamfunction2d(y,x,si_f): plt.figure(3) stf= plt.contour(y,x,si_f,50) stf1 = plt.colorbar(stf) plt.savefig('location of saved image',format='png',dpi=1200) plt.close(3) ############################################################################### def tracer2d(y,x,ti_f): plt.figure(1) trc= plt.contour(y,x,ti_f,25) trc1 = plt.colorbar(trc) plt.clabel(trc,fmt='%.0f',inline=true) plt.savefig('location of saved image',format='png',dpi=1200) plt.close(1) plt.figure(2) trp = plt.pcolormesh(y,x,ti_f,linestyle='dashed') ## alternate method of creating filled-contour plots. plt.savefig('location of saved image',format='png',dpi=1200) plt.close(2) ############################################################################### flowtime =np.linspace(500,600,2) ## here include multiple flow times. want save plots each flow time in location provided. timestep = np.zeros(len(flowtime)) n in range(len(flowtime)): timestep = (flowtime-ft_init)/delt + ts_init timestep = np.array(np.round(timestep,-2),dtype = 'int') p in range(len(timestep)): timestepstring=str(timestep[p]).zfill(4) fname = path+"ddn150ae-"+timestepstring+".txt" f = open(fname,'r') data = np.loadtxt(f,skiprows=1) data = data[data[:, 1].argsort()] data = data[np.logical_not(data[:,11]== 0)] y = data[:,2] limit = np.nonzero(y==dj_length)[0][0] y = y[limit:] vf = data[:,11] vf = vf[limit:] tr = data[:,9] tr = tr[limit:] x = data[:,1] x = x[limit:] y = data[:,2] y = y[limit:] u = data[:,3] u = u[limit:] v = data[:,4] v = v[limit:] st = data[:,5] st = st[limit:] ############################################################################### ### following code interpolation dependent variable ## using griddata interpolation unstructured structured data # resample onto 100x100 grid nx, ny = 100,100 # (n, 2) arrays of input x,y coords , dependent values pts = np.vstack((x,y )).t vals = np.vstack((tr)) vals1 = np.vstack((st)) # new x , y coordinates grid x = np.linspace(x.min(), x.max(), nx) y = np.linspace(y.min(), y.max(), ny) r = np.meshgrid(y,x)[::-1] # (nx * ny, 2) array of x,y coordinates interpolate @ ipts = np.vstack(a.ravel() in r).t # (nx * ny, 2) array of interpolated tr values ti = griddata(pts, vals, ipts, method='nearest') ti_f = np.reshape(ti,(len(y),len(x))) tracer2d(y,x,ti_f) si = griddata(pts, vals1, ipts, method='nearest') si_f = np.reshape(si,(len(y),len(x))) streamfunction2d(y,x,si_f) location text files sample text files. image have simulation corresponding 3400 text file.
i appreciate advice or in this.
thank you
solved:
Comments
Post a Comment