def GetXY_AmanziS(path, root, time, comp): try: import fsnapshot fsnok = True except: fsnok = False # import pdb; pdb.set_trace() plotfile = os.path.join(path, root) if os.path.isdir(plotfile) & fsnok: (nx, ny, nz) = fsnapshot.fplotfile_get_size(plotfile) x = np.zeros((nx), dtype=np.float64) y = np.zeros((nx), dtype=np.float64) (y, x, npts, err) = fsnapshot.fplotfile_get_data_1d(plotfile, comp, y, x) x = np.array(xrange(100)) x = x + 0.5 else: x = np.zeros((0), dtype=np.float64) y = np.zeros((0), dtype=np.float64) return (x, y)
def GetXY_AmanziS(path, root, comp): try: import fsnapshot fsnok = True except: fsnok = False plotfile = os.path.join(path, root) if os.path.isdir(plotfile) & fsnok: (nx, ny, nz) = fsnapshot.fplotfile_get_size(plotfile) v = np.zeros((nx, ny), dtype=np.float64) (v, err) = fsnapshot.fplotfile_get_data_2d(plotfile, comp, v) (xmin, xmax, ymin, ymax, zmin, zmax) = fsnapshot.fplotfile_get_limits(plotfile) dy = (ymax - ymin) / ny y = ymin + dy * 0.5 + np.arange((ny), dtype=np.float64) * dy v = v[0] else: y = np.zeros((0), dtype=np.float64) v = np.zeros((0), dtype=np.float64) return (y, v)
def GetXY_AmanziS_1D(path, root, comp, dim): try: import fsnapshot fsnok = True except: fsnok = False # plotfile = os.path.join(path,root) plotfile = max(glob.glob(path + "/" + root + '*')) if os.path.isdir(plotfile) & fsnok: (nx, ny, nz) = fsnapshot.fplotfile_get_size(plotfile) if (dim == 1): nn = nx if (dim == 2): nn = ny x = np.zeros((nn), dtype=np.float64) y = np.zeros((nn), dtype=np.float64) (y, x, npts, err) = fsnapshot.fplotfile_get_data_1d(plotfile, comp, y, x, dim) else: y = np.zeros((0), dtype=np.float64) v = np.zeros((0), dtype=np.float64) return (x, y)
def GetXY_AmanziS(path, root, comp): try: import fsnapshot fsnok = True except: fsnok = False plotfile = os.path.join(path, root) if os.path.isdir(plotfile) & fsnok: (nx, ny, nz) = fsnapshot.fplotfile_get_size(plotfile) x = np.zeros((nx), dtype=np.float64) y = np.zeros((nx), dtype=np.float64) (y, x, npts, err) = fsnapshot.fplotfile_get_data_1d(plotfile, comp, y, x) else: x = np.zeros((0), dtype=np.float64) y = np.zeros((0), dtype=np.float64) return (x, y)
def main(infile, out_file, double, plot_file, eps_out): # get a list of variable objects that contains the information # about what to plot plt_attr, pvars = parse_infile(infile) nvar = len(pvars) # get and store the grid info nx, ny, nz = fsnapshot.fplotfile_get_size(plot_file) if not nz == -1: sys.exit("ERROR: cannot read a 3-d dataset") (xmin, xmax, ymin, ymax, zmin, zmax) = \ fsnapshot.fplotfile_get_limits(plot_file) gi = Grid(plt_attr, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax, nx=nx, ny=ny) time = fsnapshot.fplotfile_get_time(plot_file) # get the data for v in pvars: data = np.zeros( (nx, ny), dtype=np.float64) data, err = fsnapshot.fplotfile_get_data_2d(plot_file, v.name, data) if not err == 0: sys.exit("ERROR: unable to read {}".format(v.name)) v.data = np.transpose(data) # find the aspect ratio: # # aspect_ratio = "h" means horizontal # "v" means vertical # "s" means square (to some degree...) if gi.W >= 2*gi.H: aspect_ratio = "h" elif gi.H >= 1.5*gi.W: aspect_ratio = "v" else: aspect_ratio = "s" # setup the figure if double == 1: fig = plt.figure(1, (25.6, 14.4)) else: fig = plt.figure(1, (12.8, 7.2)) fig.clf() if double == 1: plt.rcParams.update({'xtick.labelsize': 20, 'ytick.labelsize': 20, 'text.fontsize': 24}) plt.rc("axes", linewidth=2.0) plt.rc("lines", markeredgewidth=2.0) plt.rc("font", size=18) else: plt.rc("font", size=plt_attr.font_size) # setup the axes axg, on_left = setup_axes(fig, aspect_ratio, nvar) # plot the data for n in range(nvar): yoffset = 0 if n in on_left: yoffset = 1 do_plot(axg[n], gi, plt_attr, pvars[n], yoffset) # 5 variables is a tricky case (since the grid stores 6) if nvar == 5 and (aspect_ratio == "h" or aspect_ratio == "s"): # turn off the last axes axg[5].axis('off') axg[5].cax.axis('off') # write the time fig.text(0.1, 0.01, "t = %g s" % (time), transform=fig.transFigure, color="k") # automatically make things look better try: fig.tight_layout(pad=2.0, w_pad=5.0) # requires matplotlib >= 1.1 except: pass if plt_attr.title is not None: fig.text(0.5, 0.95, plt_attr.title, transform=fig.transFigure, color="k", horizontalalignment="center", fontsize=16) if out_file is None: if eps_out == 1: plt.savefig("%s.eps" % (plot_file)) else: plt.savefig("%s.png" % (plot_file)) else: if eps_out == 1: plt.savefig("%s" % (out_file)) else: plt.savefig("%s" % (out_file))
def do_plot(plotfile, eps, dpi, xmax_pass, ymax_pass, zmax_pass): global var1, m1, M1, l1, var2, m2, M2, l2, var3, m3, M3, l3, var4, m4, M4, l4, var5, m5, M5, l5, epsEnuc pylab.rc("font", size=9) #-------------------------------------------------------------------------- # construct the output file name #-------------------------------------------------------------------------- outFile = os.path.normpath(plotfile) + "_all" if (not eps): outFile += ".png" else: outFile += ".eps" #-------------------------------------------------------------------------- # read in the meta-data from the plotfile #-------------------------------------------------------------------------- (nx, ny, nz) = fsnapshot.fplotfile_get_size(plotfile) time = fsnapshot.fplotfile_get_time(plotfile) (xmin, xmax, ymin, ymax, zmin, zmax) = \ fsnapshot.fplotfile_get_limits(plotfile) dx = (xmax - xmin) / nx x = xmin + numpy.arange((nx), dtype=numpy.float64) * dx dy = (ymax - ymin) / ny y = ymin + numpy.arange((ny), dtype=numpy.float64) * dy if (nz > 0): sys.exit("ERROR: 3-d not supported") extent = [xmin, xmax, ymin, ymax] if (not xmax_pass == None): extent[1] = xmax_pass if (not ymax_pass == None): extent[3] = ymax_pass ix = nx if (not xmax_pass == None): ix = int((xmax_pass - xmin) / dx) iy = ny if (not ymax_pass == None): iy = int((ymax_pass - ymin) / dy) sparseX = 0 if (ny >= 3 * nx): sparseX = 1 # read in the data # 1 data1 = numpy.zeros((nx, ny), dtype=numpy.float64) (data1, err) = fsnapshot.fplotfile_get_data_2d(plotfile, var1, data1) if (not err == 0): sys.exit(2) data1 = numpy.transpose(data1) if (l1): data1 = numpy.log10(data1) m1 = math.log10(m1) M1 = math.log10(M1) # 2 data2 = numpy.zeros((nx, ny), dtype=numpy.float64) (data2, err) = fsnapshot.fplotfile_get_data_2d(plotfile, var2, data2) if (not err == 0): sys.exit(2) data2 = numpy.transpose(data2) if (l2): data1 = numpy.log10(data2) m2 = math.log10(m2) M2 = math.log10(M2) # 3 data3 = numpy.zeros((nx, ny), dtype=numpy.float64) (data3, err) = fsnapshot.fplotfile_get_data_2d(plotfile, var3, data3) if (not err == 0): sys.exit(2) data3 = numpy.transpose(data3) if (l3): data3 = numpy.log10(data3) m3 = math.log10(m3) M3 = math.log10(M3) # 4 data4 = numpy.zeros((nx, ny), dtype=numpy.float64) (data4, err) = fsnapshot.fplotfile_get_data_2d(plotfile, var4, data4) if (not err == 0): sys.exit(2) data4 = numpy.transpose(data4) # floor values data4[data4 < epsEnuc] = epsEnuc if (l4): data4 = numpy.log10(data4) m4 = math.log10(m4) M4 = math.log10(M4) # 5 data5 = numpy.zeros((nx, ny), dtype=numpy.float64) (data5, err) = fsnapshot.fplotfile_get_data_2d(plotfile, var5, data5) if (not err == 0): sys.exit(2) data5 = numpy.transpose(data5) if (l5): data5 = numpy.log10(data5) m5 = math.log10(m5) M5 = math.log10(M5) # use an imagegrid to place all the axes close together. # see http://matplotlib.org/examples/axes_grid/demo_axes_grid2.html F = pylab.figure(1, (12, 8)) F.clf() formatter = matplotlib.ticker.ScalarFormatter(useMathText=True) formatter.set_powerlimits((-3, 3)) grid = ImageGrid( F, 111, # similar to subplot(111) nrows_ncols=(1, 5), direction="row", axes_pad=0.2, add_all=True, label_mode="L", share_all=True, cbar_location="top", cbar_mode="each", cbar_size="3%", cbar_pad="5%", ) # variable 1 ax = grid[0] im = ax.imshow(data1[0:iy, 0:ix], origin='lower', extent=extent, vmin=m1, vmax=M1) ax.set_title(var1) ax.set_xlabel("x") ax.set_ylabel("y") ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) cb = ax.cax.colorbar(im, format=formatter) #ax.cax.set_title(var1) # variable 2 ax = grid[1] im = ax.imshow(data2[0:iy, 0:ix], origin='lower', extent=extent, vmin=m2, vmax=M2) ax.set_title(var2) ax.set_xlabel("x") ax.set_ylabel("y") ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.set_xticks( [xmin, xmin + (xmax - xmin) / 3.0, xmin + 2.0 * (xmax - xmin) / 3.0]) ax.cax.colorbar(im, format=formatter) # variable 3 ax = grid[2] im = ax.imshow(data3[0:iy, 0:ix], origin='lower', extent=extent, vmin=m3, vmax=M3) ax.set_title(var3) ax.set_xlabel("x") ax.set_ylabel("y") ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.cax.colorbar(im, format=formatter) # variable 4 ax = grid[3] im = ax.imshow(data4[0:iy, 0:ix], origin='lower', extent=extent, vmin=m4, vmax=M4) ax.set_title(var4) ax.set_xlabel("x") ax.set_ylabel("y") ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.cax.colorbar(im, format=formatter) # variable 5 ax = grid[4] im = ax.imshow(data5[0:iy, 0:ix], origin='lower', extent=extent, vmin=m5, vmax=M5) ax.set_title(var5) ax.set_xlabel("x") ax.set_ylabel("y") ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.cax.colorbar(im, format=formatter) # write the time pylab.text(0.0, 0.05, "t = %g s" % (time), transform=F.transFigure) #-------------------------------------------------------------------------- # save the figure #-------------------------------------------------------------------------- try: pylab.tight_layout() # requires matplotlib > 1.1 except: pass if (not eps): pylab.savefig(outFile, bbox_inches='tight', dpi=dpi, pad_inches=0.33) else: pylab.savefig(outFile, bbox_inches='tight', pad_inches=0.33)
def _getCellCounts(self): return fsnapshot.fplotfile_get_size(self.name)
def do_plot(plotfile, outFile, eps, dpi): #-------------------------------------------------------------------------- # construct the output file name #-------------------------------------------------------------------------- if (outFile == ""): outFile = os.path.normpath(plotfile) if (not eps): outFile += ".png" else: outFile += ".eps" else: # make sure the proper extension is used if (not eps): if (not string.rfind(outFile, ".png") > 0): outFile = outFile + ".png" else: if (not string.rfind(outFile, ".eps") > 0): outFile = outFile + ".eps" #-------------------------------------------------------------------------- # read in the meta-data from the plotfile #-------------------------------------------------------------------------- (nx, ny, nz) = fsnapshot.fplotfile_get_size(plotfile) time = fsnapshot.fplotfile_get_time(plotfile) (xmin, xmax, ymin, ymax, zmin, zmax) = \ fsnapshot.fplotfile_get_limits(plotfile) #-------------------------------------------------------------------------- # get the variable information #-------------------------------------------------------------------------- nvar = fsnapshot.fplotfile_get_nvar(plotfile) varinfo = [] # note, the variable indices are 1-based, since they live in # Fortran land. n = 1 while (n <= nvar): (varname, varmin, varmax, ierr) = \ fsnapshot.fplotfile_get_varinfo(plotfile, n) if (ierr == 0): varinfo.append(var(varname.rstrip(), n, varmin, varmax)) else: print "ERROR: invalid variable name" sys.exit(2) n += 1 # n = 0 # while (n < len(varinfo)): # print varinfo[n].name, varinfo[n].index # n += 1 #-------------------------------------------------------------------------- # plot #-------------------------------------------------------------------------- # <<< density and temperature >>> pylab.clf() sp = pylab.subplot(311) sp.set_yscale('log') # get the density x = numpy.zeros((nx), dtype=numpy.float64) rho = numpy.zeros((nx), dtype=numpy.float64) (rho, x, npts, err) = \ fsnapshot.fplotfile_get_data_1d(plotfile, "density", rho, x) if (not err == 0): sys.exit(2) # get the temperature T = numpy.zeros((nx), dtype=numpy.float64) (T, x, npts, err) = \ fsnapshot.fplotfile_get_data_1d(plotfile, "tfromp", T, x) if (not err == 0): sys.exit(2) # density plot pylab.plot(x, T, color="blue") pylab.ylabel(r"temperature (K)", color="blue") ax = pylab.gca() # the offset text is the 1.e8 that appears under the axis labels # when doing scientific notation ax.tick_params(labeltop='off') ax.tick_params(labelbottom='off') ax.xaxis.offsetText.set_visible(False) # temperature plot sp2 = pylab.twinx() sp2.set_yscale('log') pylab.plot(x, rho, color="red") pylab.ylabel(r"density (g cm$^{-3}$)", color="red") # <<< species >>> sp = pylab.subplot(312) # find where the species lie n = 0 nSpeciesStart = -1 nSpeciesEnd = -1 while (n < len(varinfo)): if (varinfo[n].name.find("X(") >= 0 and nSpeciesStart == -1): nSpeciesStart = n n += 1 continue if (varinfo[n].name.find("X(") == -1 and nSpeciesStart >= 0 and nSpeciesEnd == -1): nSpeciesEnd = n - 1 n += 1 # loop over all the species. Only plot those that have abundances # that exceed the threshold speciesPlotThresh X = numpy.zeros((nx), dtype=numpy.float64) n = nSpeciesStart while (n <= nSpeciesEnd): # is this species abundant enough? if (varinfo[n].max < speciesPlotThresh): n += 1 continue (X, x, npts, err) = \ fsnapshot.fplotfile_get_data_1d(plotfile, varinfo[n].name, X, x) if (not err == 0): sys.exit(2) pylab.plot(x, X, label=varinfo[n].name, lw=1) n += 1 leg = pylab.legend(loc=1, labelspacing=0.1) ltext = leg.get_texts() pylab.setp(ltext, fontsize='small') leg.draw_frame(0) ax = pylab.gca() # the offset text is the 1.e8 that appears under the axis labels # when doing scientific notation ax.tick_params(labeltop='off') ax.tick_params(labelbottom='off') ax.xaxis.offsetText.set_visible(False) # <<< enuc >>> sp = pylab.subplot(313) #sp.set_yscale('log') # get enuc enuc = numpy.zeros((nx), dtype=numpy.float64) (enuc, x, npts, err) = \ fsnapshot.fplotfile_get_data_1d(plotfile, "enucdot", enuc, x) if (not err == 0): sys.exit(2) pylab.plot(x, enuc, color="blue") pylab.ylabel(r"nuclear energy generation rate (erg/g/s)") pylab.xlabel(r"x (cm)") ax = pylab.gca() ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) #-------------------------------------------------------------------------- # save the figure #-------------------------------------------------------------------------- f = pylab.gcf() f.set_size_inches(6.0, 12.0) if (not eps): pylab.savefig(outFile, bbox_inches='tight', dpi=dpi, pad_inches=0.33) else: pylab.savefig(outFile, bbox_inches='tight', pad_inches=0.33)
def do_plot(plotfile, component, component2, outFile, log, minval, maxval, minval2, maxval2, eps, dpi, origin, annotation, particles, time_ind): # plotfile plotfile to read data from # component first variable to plot # component2 optional second variable to plot # outFile save plot as "outFile" # log (= 1,0) plot log (base 10) of the data # minval (float) specify minimum data range for plot # maxval (float) specify maximum data range for plot # eps (= 1,0) make an EPS plot instead of PNG # dpi (int) (PNG only) make the plot with dpi value # origin (= 1,0) (3-d only) slice through origin (0,0,0) # annotation (2-d only) add annotation string under time # particles (2-d only) particle data # time_ind array index of time cooresponding to plotfile #---------------------- # check incoming values: #----------------------- if (plotfile == ""): print "\n---ERROR: plotfile not specified---" print " (plotsinglevar_parts.py)\n" usage() sys.exit(2) if (component == ""): print "\n---ERROR: no component specified---" print " (plotsinglevar_parts.py)\n" usage() sys.exit(2) if ((log != 1) and (log != 0)): print "\n---ERROR: invalid value for log (= 1,0)---" print " (plotsinglevar_parts.py)\n" usage() sys.exit(2) if ((eps != 1) and (eps != 0)): print "\n---ERROR: invalid value for eps (= 1,0)---" print " (plotsinglevar_parts.py)\n" usage() sys.exit(2) if (minval != None): try: minval = float(minval) except ValueError: print "\n---ERROR: invalid value for minval (= float)---" print " (plotsinglevar_parts.py)\n" usage() sys.exit(2) if (maxval != None): try: maxval = float(maxval) except ValueError: print "\n---ERROR: invalid value for maxval (= float)---" print " (plotsinglevar_parts.py)\n" usage() sys.exit(2) if (minval2 != None): try: minval2 = float(minval2) except ValueError: print "\n---ERROR: invalid value for minval2 (= float)---" print " (plotsinglevar_parts.py)\n" usage() sys.exit(2) if (maxval2 != None): try: maxval2 = float(maxval2) except ValueError: print "\n---ERROR: invalid value for maxval2 (= float)---" print " (plotsinglevar_parts.py)\n" usage() sys.exit(2) if ((origin != 1) and (origin != 0)): print "\n---ERROR: invalid value for origin (= 1,0)---" print " (plotsinglevar_parts.py)\n" usage() sys.exit(2) if (dpi != None): try: dpi = int(dpi) except ValueError: print "\n---ERROR: invalid value for dpi (= int)---" print " (plotsinglevar_parts.py)\n" usage() sys.exit(2) #-------------------------------------------------------------------------- # construct the output file name #-------------------------------------------------------------------------- if (outFile == ""): outFile = os.path.normpath(plotfile) + "_" + component if (not component2 == ""): outFile += "_" + component2 if (not eps): outFile += ".png" else: outFile += ".eps" else: # make sure the proper extension is used if (not eps): if (not string.rfind(outFile, ".png") > 0): outFile = outFile + ".png" else: if (not string.rfind(outFile, ".eps") > 0): outFile = outFile + ".eps" #-------------------------------------------------------------------------- # read in the meta-data from the plotfile #-------------------------------------------------------------------------- (nx, ny, nz) = fsnapshot.fplotfile_get_size(plotfile) time = fsnapshot.fplotfile_get_time(plotfile) (xmin, xmax, ymin, ymax, zmin, zmax) = \ fsnapshot.fplotfile_get_limits(plotfile) x = xmin + numpy.arange( (nx), dtype=numpy.float64 )*(xmax - xmin)/nx y = ymin + numpy.arange( (ny), dtype=numpy.float64 )*(ymax - ymin)/ny if (nz > 0): z = zmin + numpy.arange( (nz), dtype=numpy.float64 )*(zmax - zmin)/nz if (nz == -1): #---------------------------------------------------------------------- # 2-d plots #---------------------------------------------------------------------- extent = xmin, xmax, ymin, ymax # read in the main component data = numpy.zeros( (nx, ny), dtype=numpy.float64) (data, err) = fsnapshot.fplotfile_get_data_2d(plotfile, component, data) if (not err == 0): sys.exit(2) data = numpy.transpose(data) if (minval == None): minval = numpy.min(data) if (maxval == None): maxval = numpy.max(data) # read in the component #2, if present if (not component2 == ""): data2 = numpy.zeros( (nx, ny), dtype=numpy.float64) (data2, err) = fsnapshot.fplotfile_get_data_2d(plotfile, component2, data2) if (not err == 0): sys.exit(2) data2 = numpy.transpose(data2) if (minval2 == None): minval2 = numpy.min(data2) if (maxval2 == None): maxval2 = numpy.max(data2) if log: data = numpy.log10(data) if (not component2 == ""): data2 = numpy.log10(data2) minval2 = math.log10(minval2) maxval2 = math.log10(maxval2) minval = math.log10(minval) maxval = math.log10(maxval) #---------------------------------------------------------------------- # plot main component #---------------------------------------------------------------------- if (not component2 == ""): ax = pylab.subplot(1,2,1) pylab.subplots_adjust(wspace=0.5) else: ax = pylab.subplot(1,1,1) divider = mpl_toolkits.axes_grid1.make_axes_locatable(ax) im=pylab.imshow(data,origin='lower', extent=extent, vmin=minval, vmax=maxval) #---------------------------------------------------------------------- # plot the particle data #---------------------------------------------------------------------- n=0 while(n < len(particles)): # sometimes the length of particle history is larger than index if (time_ind < len(particles[n].history)): pylab.scatter(particles[n].history[time_ind].xyz[0], particles[n].history[time_ind].xyz[1], s=0.5,c='black',marker='o') n += 1 pylab.title(component) pylab.xlabel("x") pylab.ylabel("y") # axis labels in scientific notation with LaTeX ax = pylab.gca() ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) # make space for a colorbar -- getting it the same size as the # vertical extent of the plot is surprisingly tricky. See # http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html#colorbar-whose-height-or-width-in-sync-with-the-master-axes ax_cb = divider.new_horizontal(size="10%", pad=0.1) fig1 = ax.get_figure() fig1.add_axes(ax_cb) formatter = matplotlib.ticker.ScalarFormatter(useMathText=True) cb = pylab.colorbar(im, format=formatter, cax=ax_cb) # make the font size for the colorbar axis labels small. Note #---------------------------------------------------------------------- # plot component #2 #---------------------------------------------------------------------- if (not component2 == ""): ax = pylab.subplot(1,2,2) divider = mpl_toolkits.axes_grid1.make_axes_locatable(ax) im = pylab.imshow(data2, origin='lower', extent=extent, vmin=minval2, vmax=maxval2) #---------------------------------------------------------------- # plot the particle data #---------------------------------------------------------------- n=0 while(n < len(particles)): # sometimes the length of particle history is larger than index if (time_ind < len(particles[n].history)): pylab.scatter(particles[n].history[time_ind].xyz[0], particles[n].history[time_ind].xyz[1], s=0.5,c='black',marker='o') n += 1 pylab.title(component2) pylab.xlabel("x") pylab.ylabel("y") # axis labels in scientific notation with LaTeX ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) # make space for a colorbar -- getting it the same size as # the vertical extent of the plot is surprisingly tricky. # See # http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html#colorbar-whose-height-or-width-in-sync-with-the-master-axes ax_cb = divider.new_horizontal(size="10%", pad=0.1) fig1 = ax.get_figure() fig1.add_axes(ax_cb) formatter = matplotlib.ticker.ScalarFormatter(useMathText=True) cb = pylab.colorbar(im, format=formatter, cax=ax_cb) # make the font size for the colorbar axis labels small. Note the # offsetText is the 10^N that appears at the top of the y-axis. cl = pylab.getp(cb.ax, 'ymajorticklabels') pylab.setp(cl, fontsize=10) cb.ax.yaxis.offsetText.set_fontsize("small") #ax_cb.yaxis.tick_right() else: #---------------------------------------------------------------------- # 3-d plot #---------------------------------------------------------------------- ################################### # NOT SUPPORTED YET ################################### print "\n\n--- ERROR: 3-d not yet implemented ---" print " (plotsinglevar_parts.py)\n" sys.exit(2) # figure out the maximum width -- we will plot xy, xz, and yz w1 = xmax - xmin # also w2 w3 = ymax - ymin if (w3 > w1): scale = w3 else: scale = w1 # starting points for the figure positions # assume that the width of the plotting area is 0.05 to 0.95, # leaving 0.9 to be split amongst the 3 plots. So each has a # width of 0.3 # for the height, we will assume that the colorbar at the # bottom gets 0.15, and that we go until 0.95, leaving 0.8 of # height for the plots. pos1 = [0.05, 0.15, 0.3, 0.8] pos2 = [0.35, 0.15, 0.3, 0.8] pos3 = [0.65, 0.15, 0.3, 0.8] fig = pylab.figure() # x-y extent = xmin, xmax, ymin, ymax # read in the main component data = numpy.zeros( (nx, ny), dtype=numpy.float64) indir = 3 (data, err) = \ fsnapshot.fplotfile_get_data_3d(plotfile, component, indir, origin, data) if (not err == 0): sys.exit(2) data = numpy.transpose(data) if log: data = numpy.log10(data) if (not minval == None): minval = math.log10(minval) if (not maxval == None): maxval = math.log10(maxval) ax = pylab.subplot(1,3,1) pylab.subplots_adjust(wspace=0.4) #fig.add_axes(pos1) im=pylab.imshow(data,origin='lower', extent=extent, vmin=minval, vmax=maxval, axes=pos1) pylab.xlabel("x") pylab.ylabel("y") # axis labels in scientific notation with LaTeX ax = pylab.gca() ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.xaxis.offsetText.set_fontsize("small") ax.yaxis.offsetText.set_fontsize("small") cl = pylab.getp(ax, 'ymajorticklabels') pylab.setp(cl, fontsize=10) cl = pylab.getp(ax, 'xmajorticklabels') pylab.setp(cl, fontsize=10) # do a fixed offset in pixels from the (xmin,ymin) data point fig1 = ax.get_figure() trans=matplotlib.transforms.offset_copy(ax.transData, x=0, y=-0.5, fig=fig1, units='inches') pylab.text(xmin, ymin, "time = %7.3g s" % (time), verticalalignment="bottom", transform = trans, clip_on=False, fontsize=10) # x-z extent = xmin, xmax, zmin, zmax # read in the main component data = numpy.zeros( (nx, nz), dtype=numpy.float64) (data, err) = \ fsnapshot.fplotfile_get_data_3d(plotfile, component, 2, origin, data) if (not err == 0): sys.exit(2) data = numpy.transpose(data) if log: data = numpy.log10(data) if (not minval == None): minval = math.log10(minval) if (not maxval == None): maxval = math.log10(maxval) ax = pylab.subplot(1,3,2) #fig.add_axes(pos2) im=pylab.imshow(data,origin='lower', extent=extent, vmin=minval, vmax=maxval, axes=pos2) pylab.xlabel("x") pylab.ylabel("z") # axis labels in scientific notation with LaTeX ax = pylab.gca() ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.xaxis.offsetText.set_fontsize("small") ax.yaxis.offsetText.set_fontsize("small") cl = pylab.getp(ax, 'ymajorticklabels') pylab.setp(cl, fontsize=10) cl = pylab.getp(ax, 'xmajorticklabels') pylab.setp(cl, fontsize=10) # y-z extent = ymin, ymax, zmin, zmax # read in the main component data = numpy.zeros( (ny, nz), dtype=numpy.float64) (data, err) = \ fsnapshot.fplotfile_get_data_3d(plotfile, component, 1, origin, data) if (not err == 0): sys.exit(2) data = numpy.transpose(data) if log: data = numpy.log10(data) if (not minval == None): minval = math.log10(minval) if (not maxval == None): maxval = math.log10(maxval) ax = pylab.subplot(1,3,3) #fig.add_axes(pos3) im=pylab.imshow(data,origin='lower', extent=extent, vmin=minval, vmax=maxval, axes=pos3) pylab.xlabel("y") pylab.ylabel("z") # axis labels in scientific notation with LaTeX ax = pylab.gca() ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.xaxis.offsetText.set_fontsize("small") ax.yaxis.offsetText.set_fontsize("small") cl = pylab.getp(ax, 'ymajorticklabels') pylab.setp(cl, fontsize=10) cl = pylab.getp(ax, 'xmajorticklabels') pylab.setp(cl, fontsize=10) # colorbar pylab.subplots_adjust(bottom=0.1, left=0.05, right=0.95) formatter = matplotlib.ticker.ScalarFormatter(useMathText=True) cax = pylab.axes([0.05, 0.06, 0.9, 0.04]) pylab.colorbar(orientation="horizontal", cax=cax, format=formatter) pylab.title(component) #-------------------------------------------------------------------------- # save the figure #-------------------------------------------------------------------------- if (not eps): pylab.savefig(outFile, bbox_inches='tight', dpi=dpi, pad_inches=0.33) else: pylab.savefig(outFile, bbox_inches='tight', pad_inches=0.33)
def do_plot(plotfile, component, component2, outFile, log, minval, maxval, minval2, maxval2, eps, dpi, origin, annotation, xmin_pass, ymin_pass, zmin_pass, xmax_pass, ymax_pass, zmax_pass): pylab.rc("font", size=9) #-------------------------------------------------------------------------- # construct the output file name #-------------------------------------------------------------------------- if (outFile == ""): outFile = os.path.normpath(plotfile) + "_" + component if (not component2 == ""): outFile += "_" + component2 if (not eps): outFile += ".png" else: outFile += ".eps" else: # make sure the proper extension is used if (not eps): if (not string.rfind(outFile, ".png") > 0): outFile = outFile + ".png" else: if (not string.rfind(outFile, ".eps") > 0): outFile = outFile + ".eps" #-------------------------------------------------------------------------- # read in the meta-data from the plotfile #-------------------------------------------------------------------------- (nx, ny, nz) = fsnapshot.fplotfile_get_size(plotfile) time = fsnapshot.fplotfile_get_time(plotfile) (xmin, xmax, ymin, ymax, zmin, zmax) = \ fsnapshot.fplotfile_get_limits(plotfile) dx = (xmax - xmin) / nx x = xmin + numpy.arange((nx), dtype=numpy.float64) * dx dy = (ymax - ymin) / ny y = ymin + numpy.arange((ny), dtype=numpy.float64) * dy if (nz > 0): dz = (zmax - zmin) / nz z = zmin + numpy.arange((nz), dtype=numpy.float64) * dz if (nz == -1): #---------------------------------------------------------------------- # 2-d plots #---------------------------------------------------------------------- extent = [xmin, xmax, ymin, ymax] ix0 = 0 ix = nx iy0 = 0 iy = ny if (not xmin_pass == None): extent[0] = xmin_pass ix0 = int((xmin_pass - xmin) / dx) if (not ymin_pass == None): extent[2] = ymin_pass iy0 = int((ymin_pass - ymin) / dy) if (not xmax_pass == None): extent[1] = xmax_pass ix = int((xmax_pass - xmin) / dx) if (not ymax_pass == None): extent[3] = ymax_pass iy = int((ymax_pass - ymin) / dy) sparseX = 0 if (ny >= 3 * nx): sparseX = 1 # read in the main component data = numpy.zeros((nx, ny), dtype=numpy.float64) (data, err) = fsnapshot.fplotfile_get_data_2d(plotfile, component, data) if (not err == 0): sys.exit(2) data = numpy.transpose(data) # read in the component #2, if present if (not component2 == ""): data2 = numpy.zeros((nx, ny), dtype=numpy.float64) (data2, err) = fsnapshot.fplotfile_get_data_2d(plotfile, component2, data2) if (not err == 0): sys.exit(2) data2 = numpy.transpose(data2) # log? if log: if (numpy.min(data) < 0): data = numpy.log10(numpy.abs(data)) else: data = numpy.log10(data) if (not component2 == ""): if (numpy.min(data2) < 0.0): data2 = numpy.log10(numpy.abs(data2)) else: data2 = numpy.log10(data2) if (not minval == None): minval = math.log10(minval) if (not maxval == None): maxval = math.log10(maxval) if (not minval2 == None): minval2 = math.log10(minval2) if (not maxval2 == None): maxval2 = math.log10(maxval2) #---------------------------------------------------------------------- # plot main component #---------------------------------------------------------------------- if (not component2 == ""): ax = pylab.subplot(1, 2, 1) pylab.subplots_adjust(wspace=0.5) else: ax = pylab.subplot(1, 1, 1) divider = mpl_toolkits.axes_grid1.make_axes_locatable(ax) im = pylab.imshow(data[iy0:iy, ix0:ix], origin='lower', extent=extent, vmin=minval, vmax=maxval) pylab.title(component) pylab.xlabel("x") pylab.ylabel("y") # axis labels in scientific notation with LaTeX ax = pylab.gca() ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) if (sparseX): ax.xaxis.set_major_locator(pylab.MaxNLocator(3)) # make space for a colorbar -- getting it the same size as the # vertical extent of the plot is surprisingly tricky. See # http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html#colorbar-whose-height-or-width-in-sync-with-the-master-axes ax_cb = divider.new_horizontal(size="10%", pad=0.1) fig1 = ax.get_figure() fig1.add_axes(ax_cb) formatter = matplotlib.ticker.ScalarFormatter(useMathText=True) cb = pylab.colorbar(im, format=formatter, cax=ax_cb) # make the font size for the colorbar axis labels small. Note # the offsetText is the 10^N that appears at the top of the # y-axis. cl = pylab.getp(cb.ax, 'ymajorticklabels') pylab.setp(cl, fontsize=10) cb.ax.yaxis.offsetText.set_fontsize("small") # do a fixed offset in pixels from the (xmin,ymin) data point trans = matplotlib.transforms.offset_copy(ax.transData, x=0, y=-0.5, fig=fig1, units='inches') pylab.text(xmin, ymin, "time = %7.3g s" % (time), verticalalignment="bottom", transform=trans, clip_on=False, fontsize=10) if (not annotation == ""): trans = matplotlib.transforms.offset_copy(ax.transData, x=0, y=-0.65, fig=fig1, units='inches') pylab.text(xmin, ymin, "%s" % (annotation), verticalalignment="bottom", transform=trans, clip_on=False, fontsize=10) #---------------------------------------------------------------------- # plot component #2 #---------------------------------------------------------------------- if (not component2 == ""): ax = pylab.subplot(1, 2, 2) divider = mpl_toolkits.axes_grid1.make_axes_locatable(ax) im = pylab.imshow(data2[iy0:iy, ix0:ix], origin='lower', extent=extent, vmin=minval2, vmax=maxval2) pylab.title(component2) pylab.xlabel("x") pylab.ylabel("y") # axis labels in scientific notation with LaTeX ax.xaxis.set_major_formatter( pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter( pylab.ScalarFormatter(useMathText=True)) if (sparseX): ax.xaxis.set_major_locator(pylab.MaxNLocator(3)) # make space for a colorbar -- getting it the same size as # the vertical extent of the plot is surprisingly tricky. # See # http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html#colorbar-whose-height-or-width-in-sync-with-the-master-axes ax_cb = divider.new_horizontal(size="10%", pad=0.1) fig1 = ax.get_figure() fig1.add_axes(ax_cb) formatter = matplotlib.ticker.ScalarFormatter(useMathText=True) cb = pylab.colorbar(im, format=formatter, cax=ax_cb) # make the font size for the colorbar axis labels small. Note the # offsetText is the 10^N that appears at the top of the y-axis. cl = pylab.getp(cb.ax, 'ymajorticklabels') pylab.setp(cl, fontsize=10) cb.ax.yaxis.offsetText.set_fontsize("small") #ax_cb.yaxis.tick_right() else: #---------------------------------------------------------------------- # 3-d plot #---------------------------------------------------------------------- # starting points for the figure positions # assume that the width of the plotting area is 0.05 to 0.95, # leaving 0.9 to be split amongst the 3 plots. So each has a # width of 0.3 # for the height, we will assume that the colorbar at the # bottom gets 0.15, and that we go until 0.95, leaving 0.8 of # height for the plots. pos1 = [0.05, 0.15, 0.3, 0.8] pos2 = [0.35, 0.15, 0.3, 0.8] pos3 = [0.65, 0.15, 0.3, 0.8] fig = pylab.figure() # read in the slices # x-y data_xy = numpy.zeros((nx, ny), dtype=numpy.float64) indir = 3 (data_xy, err) = \ fsnapshot.fplotfile_get_data_3d(plotfile, component, indir, origin, data_xy) if (not err == 0): sys.exit(2) data_xy = numpy.transpose(data_xy) if log: if (numpy.min(data_xy) < 0): data_xy = numpy.log10(numpy.abs(data_xy)) else: data_xy = numpy.log10(data_xy) # x-z data_xz = numpy.zeros((nx, nz), dtype=numpy.float64) (data_xz, err) = \ fsnapshot.fplotfile_get_data_3d(plotfile, component, 2, origin, data_xz) if (not err == 0): sys.exit(2) data_xz = numpy.transpose(data_xz) if log: if (numpy.min(data_xz) < 0): data_xz = numpy.log10(numpy.abs(data_xz)) else: data_xz = numpy.log10(data_xz) # y-z data_yz = numpy.zeros((ny, nz), dtype=numpy.float64) (data_yz, err) = \ fsnapshot.fplotfile_get_data_3d(plotfile, component, 1, origin, data_yz) if (not err == 0): sys.exit(2) data_yz = numpy.transpose(data_yz) if log: if (numpy.min(data_yz) < 0): data_yz = numpy.log10(numpy.abs(data_yz)) else: data_yz = numpy.log10(data_yz) if (not minval == None): if (log): minval = math.log10(minval) else: minval = numpy.min(data_xy) minval = min(minval, numpy.min(data_xz)) minval = min(minval, numpy.min(data_yz)) if (not maxval == None): if (log): maxval = math.log10(maxval) else: maxval = numpy.max(data_xy) maxval = max(maxval, numpy.max(data_xz)) maxval = max(maxval, numpy.max(data_yz)) # x-y extent = [xmin, xmax, ymin, ymax] ix0 = 0 ix = nx iy0 = 0 iy = ny if (not xmin_pass == None): extent[0] = xmin_pass ix0 = int((xmin_pass - xmin) / dx) if (not ymin_pass == None): extent[2] = ymin_pass iy0 = int((ymin_pass - ymin) / dy) if (not xmax_pass == None): extent[1] = xmax_pass ix = int((xmax_pass - xmin) / dx) if (not ymax_pass == None): extent[3] = ymax_pass iy = int((ymax_pass - ymin) / dy) ax = pylab.subplot(1, 3, 1) pylab.subplots_adjust(wspace=0.4) #fig.add_axes(pos1) im = pylab.imshow(data_xy[iy0:iy, ix0:ix], origin='lower', extent=extent, vmin=minval, vmax=maxval, axes=pos1) pylab.xlabel("x") pylab.ylabel("y") # axis labels in scientific notation with LaTeX ax = pylab.gca() ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.xaxis.offsetText.set_fontsize("small") ax.yaxis.offsetText.set_fontsize("small") cl = pylab.getp(ax, 'ymajorticklabels') pylab.setp(cl, fontsize=10) cl = pylab.getp(ax, 'xmajorticklabels') pylab.setp(cl, fontsize=10) # do a fixed offset in pixels from the (xmin,ymin) data point fig1 = ax.get_figure() trans = matplotlib.transforms.offset_copy(ax.transData, x=0, y=-0.5, fig=fig1, units='inches') # pylab.text(xmin_pass, ymin_pass, "time = %7.3g s" % (time), # verticalalignment="bottom", transform = trans, # clip_on=False, fontsize=10) # x-z extent = [xmin, xmax, zmin, zmax] ix0 = 0 ix = nx iz0 = 0 iz = nz if (not xmin_pass == None): extent[0] = xmin_pass ix0 = int((xmin_pass - xmin) / dx) if (not zmin_pass == None): extent[2] = zmin_pass iz0 = int((zmin_pass - zmin) / dz) if (not xmax_pass == None): extent[1] = xmax_pass ix = int((xmax_pass - xmin) / dx) if (not zmax_pass == None): extent[3] = zmax_pass iz = int((zmax_pass - zmin) / dz) ax = pylab.subplot(1, 3, 2) #fig.add_axes(pos2) im = pylab.imshow(data_xz[iz0:iz, ix0:ix], origin='lower', extent=extent, vmin=minval, vmax=maxval, axes=pos2) pylab.xlabel("x") pylab.ylabel("z") # axis labels in scientific notation with LaTeX ax = pylab.gca() ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.xaxis.offsetText.set_fontsize("small") ax.yaxis.offsetText.set_fontsize("small") cl = pylab.getp(ax, 'ymajorticklabels') pylab.setp(cl, fontsize=10) cl = pylab.getp(ax, 'xmajorticklabels') pylab.setp(cl, fontsize=10) # y-z extent = [ymin, ymax, zmin, zmax] iy0 = 0 iy = ny iz0 = 0 iz = nz if (not ymin_pass == None): extent[0] = ymin_pass iy0 = int((ymin_pass - ymin) / dy) if (not zmin_pass == None): extent[2] = zmin_pass iz0 = int((zmin_pass - zmin) / dz) if (not ymax_pass == None): extent[1] = ymax_pass iy = int((ymax_pass - ymin) / dy) if (not zmax_pass == None): extent[3] = zmax_pass iz = int((zmax_pass - zmin) / dz) ax = pylab.subplot(1, 3, 3) #fig.add_axes(pos3) im = pylab.imshow(data_yz[iz0:iz, iy0:iy], origin='lower', extent=extent, vmin=minval, vmax=maxval, axes=pos3) pylab.xlabel("y") pylab.ylabel("z") # axis labels in scientific notation with LaTeX ax = pylab.gca() ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.xaxis.offsetText.set_fontsize("small") ax.yaxis.offsetText.set_fontsize("small") cl = pylab.getp(ax, 'ymajorticklabels') pylab.setp(cl, fontsize=10) cl = pylab.getp(ax, 'xmajorticklabels') pylab.setp(cl, fontsize=10) # colorbar pylab.subplots_adjust(bottom=0.1, left=0.05, right=0.95) formatter = matplotlib.ticker.ScalarFormatter(useMathText=True) cax = pylab.axes([0.05, 0.06, 0.9, 0.04]) pylab.colorbar(orientation="horizontal", cax=cax, format=formatter) pylab.title(component) #-------------------------------------------------------------------------- # save the figure #-------------------------------------------------------------------------- # try: pylab.tight_layout() # requires matplotlib >= 1.1 # except: # pass if (not eps): pylab.savefig(outFile, bbox_inches='tight', dpi=dpi, pad_inches=0.33) else: pylab.savefig(outFile) #, bbox_inches='tight', pad_inches=0.33)
def do_plot(plotfile1, plotfile2, plotfile3, component, outFile, log, minval, maxval, ncontours, eps, dpi, xmin, xmax, ymin, ymax, label1, label2, label3): #-------------------------------------------------------------------------- # construct the output file name #-------------------------------------------------------------------------- if (outFile == ""): outFile = "compare_" + component if (not eps): outFile += ".png" else: outFile += ".eps" else: # make sure the proper extension is used if (not eps): if (not string.rfind(outFile, ".png") > 0): outFile = outFile + ".png" else: if (not string.rfind(outFile, ".eps") > 0): outFile = outFile + ".eps" #-------------------------------------------------------------------------- # read in the data from plotfile1 #-------------------------------------------------------------------------- (nx, ny, nz) = fsnapshot.fplotfile_get_size(plotfile1) time = fsnapshot.fplotfile_get_time(plotfile1) (xmin1, xmax1, ymin1, ymax1, zmin1, zmax1) = \ fsnapshot.fplotfile_get_limits(plotfile1) x1 = xmin1 + numpy.arange( (nx), dtype=numpy.float64 )*(xmax1 - xmin1)/nx y1 = ymin1 + numpy.arange( (ny), dtype=numpy.float64 )*(ymax1 - ymin1)/ny if (not nz == -1): print "ERROR: 2-d support only" sys.exit(2) # read in the main component data1 = numpy.zeros( (nx, ny), dtype=numpy.float64) (data1, err) = fsnapshot.fplotfile_get_data_2d(plotfile1, component, data1) if (not err == 0): sys.exit(2) data1 = numpy.transpose(data1) if log: data1 = numpy.log10(data1) extent1 = [xmin1, xmax1, ymin1, ymax1] #-------------------------------------------------------------------------- # read in the data from plotfile2 #-------------------------------------------------------------------------- (nx, ny, nz) = fsnapshot.fplotfile_get_size(plotfile2) time = fsnapshot.fplotfile_get_time(plotfile2) (xmin2, xmax2, ymin2, ymax2, zmin2, zmax2) = \ fsnapshot.fplotfile_get_limits(plotfile2) x2 = xmin2 + numpy.arange( (nx), dtype=numpy.float64 )*(xmax2 - xmin2)/nx y2 = ymin2 + numpy.arange( (ny), dtype=numpy.float64 )*(ymax2 - ymin2)/ny if (not nz == -1): print "ERROR: 2-d support only" sys.exit(2) # read in the main component data2 = numpy.zeros( (nx, ny), dtype=numpy.float64) (data2, err) = fsnapshot.fplotfile_get_data_2d(plotfile2, component, data2) if (not err == 0): sys.exit(2) data2 = numpy.transpose(data2) if log: data2 = numpy.log10(data2) extent2 = [xmin2, xmax2, ymin2, ymax2] #-------------------------------------------------------------------------- # read in the data from plotfile3 -- if present #-------------------------------------------------------------------------- if (not plotfile3 == ""): (nx, ny, nz) = fsnapshot.fplotfile_get_size(plotfile3) time = fsnapshot.fplotfile_get_time(plotfile3) (xmin3, xmax3, ymin3, ymax3, zmin3, zmax3) = \ fsnapshot.fplotfile_get_limits(plotfile3) x3 = xmin3 + numpy.arange( (nx), dtype=numpy.float64 )*(xmax3 - xmin3)/nx y3 = ymin3 + numpy.arange( (ny), dtype=numpy.float64 )*(ymax3 - ymin3)/ny if (not nz == -1): print "ERROR: 2-d support only" sys.exit(2) # read in the main component data3 = numpy.zeros( (nx, ny), dtype=numpy.float64) (data3, err) = fsnapshot.fplotfile_get_data_2d(plotfile3, component, data3) if (not err == 0): sys.exit(2) data3 = numpy.transpose(data3) if log: data3 = numpy.log10(data3) extent3 = [xmin3, xmax3, ymin3, ymax3] #-------------------------------------------------------------------------- # find data limits, etc. #-------------------------------------------------------------------------- if (not extent1 == extent2): print "ERROR: extent of domains do not agree" sys.exit(2) if (not plotfile3 == ""): if (not extent1 == extent3): print "ERROR: extent of domains do not agree" sys.exit(2) extent = extent1 if (not xmin == None): extent[0] = xmin if (not xmax == None): extent[1] = xmax if (not ymin == None): extent[2] = ymin if (not ymax == None): extent[3] = ymax if (minval == None): minval = min(numpy.min(data1), numpy.min(data2)) if (not plotfile3 == ""): minval = min(minval, numpy.min(data3)) if (maxval == None): maxval = max(numpy.max(data1), numpy.max(data2)) if (not plotfile3 == ""): maxval = max(maxval, numpy.max(data3)) levels = numpy.linspace(minval, maxval, ncontours, endpoint=True) #-------------------------------------------------------------------------- # make the figure #-------------------------------------------------------------------------- cs1 = pylab.contour(x1, y1, data1, ncontours, colors='k', levels=levels) cs2 = pylab.contour(x2, y2, data2, ncontours, colors='r', levels=levels) if (not plotfile3 == ""): cs3 = pylab.contour(x3, y3, data3, ncontours, colors='g', levels=levels) # make the labels -- see http://www.scipy.org/Cookbook/Matplotlib/Legend # for this technique lines = [] labels = [] if (not label1 == None): line1 = matplotlib.lines.Line2D(range(10), range(10), linestyle='-', color='k') lines.append(line1) labels.append(label1) if (not label2 == None): line2 = matplotlib.lines.Line2D(range(10), range(10), linestyle='-', color='r') lines.append(line2) labels.append(label2) if (not label3 == None): line3 = matplotlib.lines.Line2D(range(10), range(10), linestyle='-', color='g') lines.append(line3) labels.append(label3) pylab.legend(lines, labels, fontsize="small", frameon=False) formatter = matplotlib.ticker.ScalarFormatter(useMathText=True) #pylab.clabel(cs, fontsize=9, inline=1)#, fmt=formatter) pylab.axis(extent) ax = pylab.gca() ax.set_aspect("equal") fig1 = ax.get_figure() ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) pylab.xlabel("x") pylab.ylabel("y") if (not eps): pylab.savefig(outFile, bbox_inches='tight', dpi=dpi, pad_inches=0.5) else: pylab.savefig(outFile, bbox_inches='tight', pad_inches=0.5)
def do_plot(plotfile, component, component2, outFile, log, minval, maxval, minval2, maxval2, eps, dpi, origin, annotation, xmin_pass, ymin_pass, zmin_pass, xmax_pass, ymax_pass, zmax_pass): pylab.rc("font", size=9) #-------------------------------------------------------------------------- # construct the output file name #-------------------------------------------------------------------------- if (outFile == ""): outFile = os.path.normpath(plotfile) + "_" + component if (not component2 == ""): outFile += "_" + component2 if (not eps): outFile += ".png" else: outFile += ".eps" else: # make sure the proper extension is used if (not eps): if (not string.rfind(outFile, ".png") > 0): outFile = outFile + ".png" else: if (not string.rfind(outFile, ".eps") > 0): outFile = outFile + ".eps" #-------------------------------------------------------------------------- # read in the meta-data from the plotfile #-------------------------------------------------------------------------- (nx, ny, nz) = fsnapshot.fplotfile_get_size(plotfile) time = fsnapshot.fplotfile_get_time(plotfile) (xmin, xmax, ymin, ymax, zmin, zmax) = \ fsnapshot.fplotfile_get_limits(plotfile) dx = (xmax - xmin)/nx x = xmin + numpy.arange( (nx), dtype=numpy.float64 )*dx dy = (ymax - ymin)/ny y = ymin + numpy.arange( (ny), dtype=numpy.float64 )*dy if (nz > 0): dz = (zmax - zmin)/nz z = zmin + numpy.arange( (nz), dtype=numpy.float64 )*dz if (nz == -1): #---------------------------------------------------------------------- # 2-d plots #---------------------------------------------------------------------- extent = [xmin, xmax, ymin, ymax] ix0 = 0 ix = nx iy0 = 0 iy = ny if (not xmin_pass == None): extent[0] = xmin_pass ix0 = int((xmin_pass - xmin)/dx) if (not ymin_pass == None): extent[2] = ymin_pass iy0 = int((ymin_pass - ymin)/dy) if (not xmax_pass == None): extent[1] = xmax_pass ix = int((xmax_pass - xmin)/dx) if (not ymax_pass == None): extent[3] = ymax_pass iy = int((ymax_pass - ymin)/dy) sparseX = 0 if (ny >= 3*nx): sparseX = 1 # read in the main component data = numpy.zeros( (nx, ny), dtype=numpy.float64) (data, err) = fsnapshot.fplotfile_get_data_2d(plotfile, component, data) if (not err == 0): sys.exit(2) data = numpy.transpose(data) # read in the component #2, if present if (not component2 == ""): data2 = numpy.zeros( (nx, ny), dtype=numpy.float64) (data2, err) = fsnapshot.fplotfile_get_data_2d(plotfile, component2, data2) if (not err == 0): sys.exit(2) data2 = numpy.transpose(data2) # log? if log: if (numpy.min(data) < 0): data = numpy.log10(numpy.abs(data)) else: data = numpy.log10(data) if (not component2 == ""): if (numpy.min(data2) < 0.0): data2 = numpy.log10(numpy.abs(data2)) else: data2 = numpy.log10(data2) if (not minval == None): minval = math.log10(minval) if (not maxval == None): maxval = math.log10(maxval) if (not minval2 == None): minval2 = math.log10(minval2) if (not maxval2 == None): maxval2 = math.log10(maxval2) #---------------------------------------------------------------------- # plot main component #---------------------------------------------------------------------- if (not component2 == ""): ax = pylab.subplot(1,2,1) pylab.subplots_adjust(wspace=0.5) else: ax = pylab.subplot(1,1,1) divider = mpl_toolkits.axes_grid1.make_axes_locatable(ax) im=pylab.imshow(data[iy0:iy,ix0:ix],origin='lower', extent=extent, vmin=minval, vmax=maxval) pylab.title(component) pylab.xlabel("x") pylab.ylabel("y") # axis labels in scientific notation with LaTeX ax = pylab.gca() ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) if (sparseX): ax.xaxis.set_major_locator(pylab.MaxNLocator(3)) # make space for a colorbar -- getting it the same size as the # vertical extent of the plot is surprisingly tricky. See # http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html#colorbar-whose-height-or-width-in-sync-with-the-master-axes ax_cb = divider.new_horizontal(size="10%", pad=0.1) fig1 = ax.get_figure() fig1.add_axes(ax_cb) formatter = matplotlib.ticker.ScalarFormatter(useMathText=True) cb = pylab.colorbar(im, format=formatter, cax=ax_cb) # make the font size for the colorbar axis labels small. Note # the offsetText is the 10^N that appears at the top of the # y-axis. cl = pylab.getp(cb.ax, 'ymajorticklabels') pylab.setp(cl, fontsize=10) cb.ax.yaxis.offsetText.set_fontsize("small") # do a fixed offset in pixels from the (xmin,ymin) data point trans=matplotlib.transforms.offset_copy(ax.transData, x=0, y=-0.5, fig=fig1, units='inches') pylab.text(xmin, ymin, "time = %7.3g s" % (time), verticalalignment="bottom", transform = trans, clip_on=False, fontsize=10) if (not annotation == ""): trans=matplotlib.transforms.offset_copy(ax.transData, x=0, y=-0.65, fig=fig1, units='inches') pylab.text(xmin, ymin, "%s" % (annotation), verticalalignment="bottom", transform = trans, clip_on=False, fontsize=10) #---------------------------------------------------------------------- # plot component #2 #---------------------------------------------------------------------- if (not component2 == ""): ax = pylab.subplot(1,2,2) divider = mpl_toolkits.axes_grid1.make_axes_locatable(ax) im = pylab.imshow(data2[iy0:iy,ix0:ix], origin='lower', extent=extent, vmin=minval2, vmax=maxval2) pylab.title(component2) pylab.xlabel("x") pylab.ylabel("y") # axis labels in scientific notation with LaTeX ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) if (sparseX): ax.xaxis.set_major_locator(pylab.MaxNLocator(3)) # make space for a colorbar -- getting it the same size as # the vertical extent of the plot is surprisingly tricky. # See # http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html#colorbar-whose-height-or-width-in-sync-with-the-master-axes ax_cb = divider.new_horizontal(size="10%", pad=0.1) fig1 = ax.get_figure() fig1.add_axes(ax_cb) formatter = matplotlib.ticker.ScalarFormatter(useMathText=True) cb = pylab.colorbar(im, format=formatter, cax=ax_cb) # make the font size for the colorbar axis labels small. Note the # offsetText is the 10^N that appears at the top of the y-axis. cl = pylab.getp(cb.ax, 'ymajorticklabels') pylab.setp(cl, fontsize=10) cb.ax.yaxis.offsetText.set_fontsize("small") #ax_cb.yaxis.tick_right() else: #---------------------------------------------------------------------- # 3-d plot #---------------------------------------------------------------------- # starting points for the figure positions # assume that the width of the plotting area is 0.05 to 0.95, # leaving 0.9 to be split amongst the 3 plots. So each has a # width of 0.3 # for the height, we will assume that the colorbar at the # bottom gets 0.15, and that we go until 0.95, leaving 0.8 of # height for the plots. pos1 = [0.05, 0.15, 0.3, 0.8] pos2 = [0.35, 0.15, 0.3, 0.8] pos3 = [0.65, 0.15, 0.3, 0.8] fig = pylab.figure() # read in the slices # x-y data_xy = numpy.zeros( (nx, ny), dtype=numpy.float64) indir = 3 (data_xy, err) = \ fsnapshot.fplotfile_get_data_3d(plotfile, component, indir, origin, data_xy) if (not err == 0): sys.exit(2) data_xy = numpy.transpose(data_xy) if log: if (numpy.min(data_xy) < 0): data_xy = numpy.log10(numpy.abs(data_xy)) else: data_xy = numpy.log10(data_xy) # x-z data_xz = numpy.zeros( (nx, nz), dtype=numpy.float64) (data_xz, err) = \ fsnapshot.fplotfile_get_data_3d(plotfile, component, 2, origin, data_xz) if (not err == 0): sys.exit(2) data_xz = numpy.transpose(data_xz) if log: if (numpy.min(data_xz) < 0): data_xz = numpy.log10(numpy.abs(data_xz)) else: data_xz = numpy.log10(data_xz) # y-z data_yz = numpy.zeros( (ny, nz), dtype=numpy.float64) (data_yz, err) = \ fsnapshot.fplotfile_get_data_3d(plotfile, component, 1, origin, data_yz) if (not err == 0): sys.exit(2) data_yz = numpy.transpose(data_yz) if log: if (numpy.min(data_yz) < 0): data_yz = numpy.log10(numpy.abs(data_yz)) else: data_yz = numpy.log10(data_yz) if (not minval == None): if (log): minval = math.log10(minval) else: minval = numpy.min(data_xy) minval = min(minval,numpy.min(data_xz)) minval = min(minval,numpy.min(data_yz)) if (not maxval == None): if (log): maxval = math.log10(maxval) else: maxval = numpy.max(data_xy) maxval = max(maxval,numpy.max(data_xz)) maxval = max(maxval,numpy.max(data_yz)) # x-y extent = [xmin, xmax, ymin, ymax] ix0 = 0 ix = nx iy0 = 0 iy = ny if (not xmin_pass == None): extent[0] = xmin_pass ix0 = int((xmin_pass - xmin)/dx) if (not ymin_pass == None): extent[2] = ymin_pass iy0 = int((ymin_pass - ymin)/dy) if (not xmax_pass == None): extent[1] = xmax_pass ix = int((xmax_pass - xmin)/dx) if (not ymax_pass == None): extent[3] = ymax_pass iy = int((ymax_pass - ymin)/dy) ax = pylab.subplot(1,3,1) pylab.subplots_adjust(wspace=0.4) #fig.add_axes(pos1) im=pylab.imshow(data_xy[iy0:iy,ix0:ix],origin='lower', extent=extent, vmin=minval, vmax=maxval, axes=pos1) pylab.xlabel("x") pylab.ylabel("y") # axis labels in scientific notation with LaTeX ax = pylab.gca() ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.xaxis.offsetText.set_fontsize("small") ax.yaxis.offsetText.set_fontsize("small") cl = pylab.getp(ax, 'ymajorticklabels') pylab.setp(cl, fontsize=10) cl = pylab.getp(ax, 'xmajorticklabels') pylab.setp(cl, fontsize=10) # do a fixed offset in pixels from the (xmin,ymin) data point fig1 = ax.get_figure() trans=matplotlib.transforms.offset_copy(ax.transData, x=0, y=-0.5, fig=fig1, units='inches') # pylab.text(xmin_pass, ymin_pass, "time = %7.3g s" % (time), # verticalalignment="bottom", transform = trans, # clip_on=False, fontsize=10) # x-z extent = [xmin, xmax, zmin, zmax] ix0 = 0 ix = nx iz0 = 0 iz = nz if (not xmin_pass == None): extent[0] = xmin_pass ix0 = int((xmin_pass - xmin)/dx) if (not zmin_pass == None): extent[2] = zmin_pass iz0 = int((zmin_pass - zmin)/dz) if (not xmax_pass == None): extent[1] = xmax_pass ix = int((xmax_pass - xmin)/dx) if (not zmax_pass == None): extent[3] = zmax_pass iz = int((zmax_pass - zmin)/dz) ax = pylab.subplot(1,3,2) #fig.add_axes(pos2) im=pylab.imshow(data_xz[iz0:iz,ix0:ix],origin='lower', extent=extent, vmin=minval, vmax=maxval, axes=pos2) pylab.xlabel("x") pylab.ylabel("z") # axis labels in scientific notation with LaTeX ax = pylab.gca() ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.xaxis.offsetText.set_fontsize("small") ax.yaxis.offsetText.set_fontsize("small") cl = pylab.getp(ax, 'ymajorticklabels') pylab.setp(cl, fontsize=10) cl = pylab.getp(ax, 'xmajorticklabels') pylab.setp(cl, fontsize=10) # y-z extent = [ymin, ymax, zmin, zmax] iy0 = 0 iy = ny iz0 = 0 iz = nz if (not ymin_pass == None): extent[0] = ymin_pass iy0 = int((ymin_pass - ymin)/dy) if (not zmin_pass == None): extent[2] = zmin_pass iz0 = int((zmin_pass - zmin)/dz) if (not ymax_pass == None): extent[1] = ymax_pass iy = int((ymax_pass - ymin)/dy) if (not zmax_pass == None): extent[3] = zmax_pass iz = int((zmax_pass - zmin)/dz) ax = pylab.subplot(1,3,3) #fig.add_axes(pos3) im=pylab.imshow(data_yz[iz0:iz,iy0:iy],origin='lower', extent=extent, vmin=minval, vmax=maxval, axes=pos3) pylab.xlabel("y") pylab.ylabel("z") # axis labels in scientific notation with LaTeX ax = pylab.gca() ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.xaxis.offsetText.set_fontsize("small") ax.yaxis.offsetText.set_fontsize("small") cl = pylab.getp(ax, 'ymajorticklabels') pylab.setp(cl, fontsize=10) cl = pylab.getp(ax, 'xmajorticklabels') pylab.setp(cl, fontsize=10) # colorbar pylab.subplots_adjust(bottom=0.1, left=0.05, right=0.95) formatter = matplotlib.ticker.ScalarFormatter(useMathText=True) cax = pylab.axes([0.05, 0.06, 0.9, 0.04]) pylab.colorbar(orientation="horizontal", cax=cax, format=formatter) pylab.title(component) #-------------------------------------------------------------------------- # save the figure #-------------------------------------------------------------------------- # try: pylab.tight_layout() # requires matplotlib >= 1.1 # except: # pass if (not eps): pylab.savefig(outFile, bbox_inches='tight', dpi=dpi, pad_inches=0.33) else: pylab.savefig(outFile)#, bbox_inches='tight', pad_inches=0.33)
def do_plot(plotfile1, plotfile2, plotfile3, component, outFile, minval, maxval, color1, color2, color3, ncontours, eps, dpi, xmin, xmax, ymin, ymax, label1, label2, label3): #-------------------------------------------------------------------------- # construct the output file name #-------------------------------------------------------------------------- if (outFile == ""): outFile = "compare_" + component if (not eps): outFile += ".png" else: outFile += ".eps" else: # make sure the proper extension is used if (not eps): if (not string.rfind(outFile, ".png") > 0): outFile = outFile + ".png" else: if (not string.rfind(outFile, ".eps") > 0): outFile = outFile + ".eps" #-------------------------------------------------------------------------- # read in the data from the plotfiles #-------------------------------------------------------------------------- (nx1, ny1, nz1) = fsnapshot.fplotfile_get_size(plotfile1) time = fsnapshot.fplotfile_get_time(plotfile1) (xmin1, xmax1, ymin1, ymax1, zmin1, zmax1) = \ fsnapshot.fplotfile_get_limits(plotfile1) if (not nz1 == -1): print "ERROR: 2-d support only" sys.exit(2) (nx2, ny2, nz2) = fsnapshot.fplotfile_get_size(plotfile2) time = fsnapshot.fplotfile_get_time(plotfile2) (xmin2, xmax2, ymin2, ymax2, zmin2, zmax2) = \ fsnapshot.fplotfile_get_limits(plotfile2) if not (nx1 == nx2 and ny1 == ny2 and xmin1 == xmin2 and xmax1 == xmax2 and ymin1 == ymin2 and ymax1 == ymax2): sys.exit("ERROR: grids don't match") if not plotfile3 == None: (nx3, ny3, nz3) = fsnapshot.fplotfile_get_size(plotfile3) time = fsnapshot.fplotfile_get_time(plotfile3) (xmin3, xmax3, ymin3, ymax3, zmin3, zmax3) = \ fsnapshot.fplotfile_get_limits(plotfile3) if not (nx1 == nx3 and ny1 == ny3 and xmin1 == xmin3 and xmax1 == xmax3 and ymin1 == ymin3 and ymax1 == ymax3): sys.exit("ERROR: grids don't match") x = xmin1 + numpy.arange( (nx1), dtype=numpy.float64) * (xmax1 - xmin1) / nx1 y = ymin1 + numpy.arange( (ny1), dtype=numpy.float64) * (ymax1 - ymin1) / ny1 # read in the components data1 = numpy.zeros((nx1, ny1), dtype=numpy.float64) (data1, err1) = fsnapshot.fplotfile_get_data_2d(plotfile1, component, data1) data2 = numpy.zeros((nx2, ny2), dtype=numpy.float64) (data2, err2) = fsnapshot.fplotfile_get_data_2d(plotfile2, component, data2) if not err1 == 0 and err2 == 0: sys.exit("ERRORS while reading data") data1 = numpy.transpose(data1) data2 = numpy.transpose(data2) if not plotfile3 == None: data3 = numpy.zeros((nx3, ny3), dtype=numpy.float64) (data3, err3) = fsnapshot.fplotfile_get_data_2d(plotfile3, component, data3) if not err3 == 0: sys.exit("ERRORS while reading data") data3 = numpy.transpose(data3) extent = [xmin1, xmax1, ymin1, ymax1] #-------------------------------------------------------------------------- # find data limits, etc. #-------------------------------------------------------------------------- if (not xmin == None): extent[0] = xmin if (not xmax == None): extent[1] = xmax if (not ymin == None): extent[2] = ymin if (not ymax == None): extent[3] = ymax if (minval == None): minval = min(numpy.min(data1), numpy.min(data2)) if (maxval == None): maxval = max(numpy.max(data1), numpy.max(data2)) if not plotfile3 == None: if (minval == None): minval = min(minval, numpy.min(data3)) if (maxval == None): maxval = max(maxval, numpy.max(data3)) levels = numpy.linspace(minval, maxval, ncontours, endpoint=True) #-------------------------------------------------------------------------- # make the figure #-------------------------------------------------------------------------- # left half of data1 xx = numpy.array(x[0:nx1 / 2 + 1]) yy = numpy.array(y) dd = numpy.array(data1[:, 0:nx1 / 2 + 1]) cs1 = pylab.contour(xx, yy, dd, ncontours, colors=color1, levels=levels) xx = numpy.array(x[nx2 / 2:]) yy = numpy.array(y) dd = numpy.array(data2[:, nx2 / 2:]) cs2 = pylab.contour(xx, yy, dd, ncontours, colors=color2, levels=levels) if not plotfile3 == None: xx = numpy.array(x[0:nx1 / 2 + 1]) yy = numpy.array(y) dd = numpy.array(data3[:, 0:nx1 / 2 + 1]) cs3 = pylab.contour(xx, yy, dd, ncontours, colors=color3, levels=levels) # make the labels -- see http://www.scipy.org/Cookbook/Matplotlib/Legend # for this technique lines = [] labels = [] if (not label1 == None): line1 = matplotlib.lines.Line2D(range(10), range(10), linestyle='-', color=color1) lines.append(line1) labels.append(label1) if (not label2 == None): line2 = matplotlib.lines.Line2D(range(10), range(10), linestyle='-', color=color2) lines.append(line2) labels.append(label2) if not plotfile3 == None: if (not label3 == None): line3 = matplotlib.lines.Line2D(range(10), range(10), linestyle='-', color=color3) lines.append(line3) labels.append(label3) pylab.legend(lines, labels) formatter = matplotlib.ticker.ScalarFormatter(useMathText=True) #pylab.clabel(cs, fontsize=9, inline=1)#, fmt=formatter) pylab.axis(extent) ax = pylab.gca() ax.set_aspect("equal") fig1 = ax.get_figure() ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) pylab.xlabel("x") pylab.ylabel("y") if (not eps): pylab.savefig(outFile, bbox_inches='tight', dpi=dpi, pad_inches=0.5) else: pylab.savefig(outFile, bbox_inches='tight', pad_inches=0.5)
import sys from numpy import * from pylab import * from mpl_toolkits.mplot3d import Axes3D import matplotlib as mpl import mpl_toolkits.axes_grid as mpl_ag pf_wide = '../prob3_chain/plt00386' pf_narr = '../prob3/plt00386' #pf_wide = '../prob3_chain/plt01541' #pf_narr = '../prob3/plt01541' # pf_wide (nx, ny, nz) = fsnapshot.fplotfile_get_size(pf_wide) t = fsnapshot.fplotfile_get_time(pf_wide) (xmin, xmax, ymin, ymax, zmin, zmax) = fsnapshot.fplotfile_get_limits(pf_wide) dx = (xmax - xmin) / nx dy = (ymax - ymin) / ny x = xmin + arange( (nx), dtype=float64 )*dx y = ymin + arange( (ny), dtype=float64 )*dy u = zeros( (nx, ny), dtype=float64) (u, err) = fsnapshot.fplotfile_get_data_2d(pf_wide, 'phi', u) u = transpose(u) u_wide = zeros( (nx+1, ny+1), dtype=float64) u_wide[0:nx,0:ny] = u u_wide[nx,0:ny] = u[0,0:ny]
def do_plot(plotfile, component1, component2, outFile, minval1, maxval1, minval2, maxval2, ncontours, eps, dpi, xmin, xmax, ymin, ymax, label1, label2): print minval1, maxval1, minval2, maxval2 #-------------------------------------------------------------------------- # construct the output file name #-------------------------------------------------------------------------- if (outFile == ""): outFile = "compare_" + component1 + "_" + component2 if (not eps): outFile += ".png" else: outFile += ".eps" else: # make sure the proper extension is used if (not eps): if (not string.rfind(outFile, ".png") > 0): outFile = outFile + ".png" else: if (not string.rfind(outFile, ".eps") > 0): outFile = outFile + ".eps" #-------------------------------------------------------------------------- # read in the data from the plotfile #-------------------------------------------------------------------------- (nx, ny, nz) = fsnapshot.fplotfile_get_size(plotfile) time = fsnapshot.fplotfile_get_time(plotfile) (xmin, xmax, ymin, ymax, zmin, zmax) = \ fsnapshot.fplotfile_get_limits(plotfile) x = xmin + numpy.arange((nx), dtype=numpy.float64) * (xmax - xmin) / nx y = ymin + numpy.arange((ny), dtype=numpy.float64) * (ymax - ymin) / ny if (not nz == -1): print "ERROR: 2-d support only" sys.exit(2) # read in the first components data1 = numpy.zeros((nx, ny), dtype=numpy.float64) (data1, err1) = fsnapshot.fplotfile_get_data_2d(plotfile, component1, data1) data2 = numpy.zeros((nx, ny), dtype=numpy.float64) (data2, err2) = fsnapshot.fplotfile_get_data_2d(plotfile, component2, data2) if not err1 == 0 and err2 == 0: sys.exit(2) data1 = numpy.transpose(data1) data2 = numpy.transpose(data2) extent = [xmin, xmax, ymin, ymax] #-------------------------------------------------------------------------- # find data limits, etc. #-------------------------------------------------------------------------- if (not xmin == None): extent[0] = xmin if (not xmax == None): extent[1] = xmax if (not ymin == None): extent[2] = ymin if (not ymax == None): extent[3] = ymax if (minval1 == None): minval1 = numpy.min(data1) if (maxval1 == None): maxval1 = numpy.max(data1) if (minval2 == None): minval2 = numpy.min(data2) if (maxval2 == None): maxval2 = numpy.max(data2) levels1 = numpy.linspace(minval1, maxval1, ncontours, endpoint=True) levels2 = numpy.linspace(minval2, maxval2, ncontours, endpoint=True) print levels1 #-------------------------------------------------------------------------- # make the figure #-------------------------------------------------------------------------- cs1 = pylab.contour(x, y, data1, ncontours, colors='b', levels=levels1) cs2 = pylab.contour(x, y, data2, ncontours, colors='r', levels=levels2) # make the labels -- see http://www.scipy.org/Cookbook/Matplotlib/Legend # for this technique lines = [] labels = [] if (not label1 == None): line1 = matplotlib.lines.Line2D(range(10), range(10), linestyle='-', color='b') lines.append(line1) labels.append(label1) if (not label2 == None): line2 = matplotlib.lines.Line2D(range(10), range(10), linestyle='-', color='r') lines.append(line2) labels.append(label2) pylab.legend(lines, labels) formatter = matplotlib.ticker.ScalarFormatter(useMathText=True) #pylab.clabel(cs, fontsize=9, inline=1)#, fmt=formatter) pylab.axis(extent) ax = pylab.gca() ax.set_aspect("equal") fig1 = ax.get_figure() ax.xaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) ax.yaxis.set_major_formatter(pylab.ScalarFormatter(useMathText=True)) pylab.xlabel("x") pylab.ylabel("y") if (not eps): pylab.savefig(outFile, bbox_inches='tight', dpi=dpi, pad_inches=0.5) else: pylab.savefig(outFile, bbox_inches='tight', pad_inches=0.5)