def plot(paths, ioutputs, labels, nbins=5, alpha=0.25, ax=None, cols=None): import seren3 import matplotlib.pylab as plt import numpy as np import pickle if ax is None: fig, ax = plt.subplots() if cols is None: from seren3.utils import plot_utils cols = plot_utils.ncols(len(paths)) for path, iout, label, c in zip(paths, ioutputs, labels, cols): # fname = "%s/pickle/ConsistentTrees/fesc_filt_%05i.p" % (path, iout) # fname = "%s/pickle/ConsistentTrees/fesc_filt_no_age_limit%05i.p" % (path, iout) # fname = "%s/pickle/ConsistentTrees/fesc_multi_group_filt_%05i.p" % (path, iout) fname = "%s/pickle/ConsistentTrees/fesc_multi_group_filt_no_age_limit%05i.p" % (path, iout) with open(fname, "rb") as f: dset = pickle.load( f ) fesc = np.zeros(len(dset)); tot_mass = np.zeros(len(dset)) for i in range(len(dset)): res = dset[i].result fesc[i] = res["fesc"] tot_mass[i] = res["tot_mass"] _plot(fesc, tot_mass, label, alpha, ax, c, nbins) ax.set_xlabel(r"log$_{10}$(M$_{\mathrm{vir}}$ [M$_{\odot}$])") ax.set_ylabel(r"log$_{10}$(f$_{\mathrm{esc}}$ [%])") plt.legend() return ax
def plot_from_sims(sims, labels, cols=None, show=True, **kwargs): ''' Plots optical depth to reionization for each sim, if reion_history table exists ''' from seren3.utils import lookahead from seren3.scripts.mpi import reion_history import matplotlib.pylab as plt import numpy as np VW = "volume_weighted" fig, ax = plt.subplots() if cols == None: from seren3.utils.plot_utils import ncols cols = ncols(len(sims)) count = 0 for sim, has_more in lookahead(sims): table = reion_history.load_xHII_table(path=sim.path) vw = np.zeros(len(table)) z = np.zeros(len(table)) # Unpack the table for i in range(len(table)): vw[i] = table[i + 1][VW] z[i] = table[i + 1]["z"] # plot label = labels[count] c = cols[count] count += 1 tau, redshifts = interp_xHe(vw, z, sim) if has_more: plot(tau, redshifts, ax=ax, label=label, color=c, **kwargs) else: # last element, draw PLANCK constraints plot(tau, redshifts, ax=ax, label=label, color=c, plot_PLANCK=True, **kwargs) if show: plt.legend() plt.show(block=False) return fig, ax
def plot_mean_integrated_fesc(binned_data, linestyle='-',\ colors=None, label=True, legend=False, **kwargs): import numpy as np import matplotlib.pylab as plt from seren3.utils.plot_utils import ncols if colors is None: cmap = kwargs.pop("cmap", "jet") print "Using cmap: ", cmap colors = ncols(len(binned_data) - 1, cmap=cmap) else: assert len(colors) == len(binned_data) - 1 ax = plt.gca() for i in range(len(binned_data)): mbin = binned_data[i] x, y = (mbin.thalo, mbin.mean) if mbin.mass_bin == "All": ax.semilogy(x, y, label="All", color="k", linewidth=5, linestyle=linestyle) else: c = colors[i] lower = "%1.1f" % mbin.mass_bin upper = None if i == len(binned_data) - 2: upper = r"$\infty$" else: upper = "%1.1f" % binned_data[i + 1].mass_bin ax.semilogy(x, y, label="[%s, %s)" % (lower, upper), color=c,\ linewidth=1.5, linestyle=linestyle) if label: plt.xlabel(r"t$_{\mathrm{Lookback}}$ [Gyr]") plt.ylabel( r"$\langle \mathrm{f}_{\mathrm{esc}} \rangle$ (<t$_{\mathrm{H}}$ [%])" ) if legend: plt.legend(loc='lower right')
def plot_Mc(sims, labels, cols=None, show=False, plot_Okamoto=False): ''' Plots Mc vs z ''' import pickle import numpy as np import matplotlib.pylab as plt fig, ax = plt.subplots() if cols is None: from seren3.utils import plot_utils cols = plot_utils.ncols(len(sims)) for sim, label, c in zip(sims, labels, cols): data = pickle.load(open("%s/Mc_alpha_fit.p" % sim.path, "rb")) Mc = np.zeros(len(data)) sigma_Mc = np.zeros(len(data)) z = np.zeros(len(data)) for i in range(len(data)): result = data[i].result Mc[i], sigma_Mc[i] = result["Mc"] z[i] = result["z"] ax.semilogy(z, Mc, label=label, color=c, linewidth=1.5) if plot_Okamoto: from seren3.scripts.mpi.fbaryon import gnedin_fitting_func data = np.loadtxt('~/Mc_Okamoto08.txt', unpack=True) alpha_Okamoto = 2. z_Okamoto, Mc_Okamoto = (data[1], data[2]) raise NotImplementedError("Not finished") ax.set_xlabel(r"z") ax.set_ylabel(r"log$_{10}$(M$_{\mathrm{c}}$(z) [M$_{\odot}$])") if show: plt.legend() plt.show(block=False) return fig, ax
def plot_neighbouring_snaps(paths, ioutputs, labels, nbins=5, num_neighbours=2, alpha=0.25, ax=None, cols=None): import seren3 import matplotlib.pylab as plt import numpy as np import pickle assert(num_neighbours%2 == 0) if ax is None: fig, ax = plt.subplots() if cols is None: from seren3.utils import plot_utils cols = plot_utils.ncols(len(paths)) for path, iout, label, c in zip(paths, ioutputs, labels, cols): fesc = [] tot_mass = [] for i in range(iout - (num_neighbours/2), iout + (num_neighbours/2) + 1): # print i fname = "%s/pickle/fesc_%05i.p" % (path, i) with open(fname, "rb") as f: dset = pickle.load( f ) for i in range(len(dset)): res = dset[i].result fesc.append(res["fesc"]) tot_mass.append(res["tot_mass"]) fesc = np.array(fesc) tot_mass = np.array(tot_mass) _plot(fesc, tot_mass, label, alpha, ax, c, nbins) ax.set_xlabel(r"log$_{10}$(M$_{\mathrm{vir}}$ [M$_{\odot}$])") ax.set_ylabel(r"log$_{10}$(f$_{\mathrm{esc}}$ [%])") plt.legend() return ax
def plot_sed(agebins, zbins, Ls, SEDs, ax=None, fs=20, label_ion_freqs=False, show_legend=False, **kwargs): import numpy as np import matplotlib.pylab as plt import matplotlib.cm as cm from seren3.utils.plot_utils import ncols # ages = np.array([1, 11, 21, 31, 41, 100]) # ages=[1., 10., 100., 1000., 10000.] ages = kwargs.pop("ages", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, \ 50, 100, 502, 1005, 10005]) colors = kwargs.pop("colors", ncols(len(ages), cmap=kwargs.pop("cmap", "rainbow"))) # colors = kwargs.pop("colors", ncols(len(ages), cmap=kwargs.pop("cmap", "Set1"))) # colors = ["r", "b", "darkorange"] zbins = np.array(zbins); agebins = np.array(agebins) Z_sun = 0.02 # Solar metallicity z_idx = (np.abs(Z_sun - zbins)).argmin() if (ax is None): fig, ax = plt.subplots(figsize=(8,8)) print kwargs for age, c in zip(ages, colors): age_idx = (np.abs(age*1e6 - agebins)).argmin() print age_idx plot_every = 1 ax.semilogy(Ls[::plot_every], SEDs[:, age_idx, z_idx][::plot_every], label="%i Myr" % (float(agebins[age_idx])/1e6) if show_legend else None, color=c, **kwargs) ax.set_xlim(100, 1000) if show_legend: box = ax.get_position() ax.set_position([box.x0 - box.width * 0.05, box.y0 + box.height * 0.05, box.width, box.height * 0.9]) ax.legend(loc='center left', bbox_to_anchor=(1., 0.5), ncol=1, prop={'size':14}) # ax.legend(loc='lower right', prop={"size":16}) # Shrink current axis by 20% # box = ax.get_position() # ax.set_position([box.x0, box.y0, box.width * 0.95, box.height]) # # Put a legend to the right of the current axis # ax.legend(loc='center left', bbox_to_anchor=(1, 0.5), prop={'size': 16}) ax.set_yscale('log') ax.set_xlabel(r'$\lambda$ [$\AA$]', fontsize=fs) ax.set_ylabel(r'J$_{\lambda}$ [L$_{\odot}$ M$_{\odot}$$^{-1}$ $\AA^{-1}$]', fontsize=fs) if label_ion_freqs: HI = 912 # A HeI = 505 HeII = 228 ion_freq_ls = '-.' ax.axvline(x=HI, linestyle=ion_freq_ls, color='k') ax.axvline(x=HeI, linestyle=ion_freq_ls, color='k') ax.axvline(x=HeII, linestyle=ion_freq_ls, color='k') ypos = ax.get_ylim()[1] ypos *= 1.5 ax.text(HI, ypos, r'HI', fontsize=20, ha='center') ax.text(HeI, ypos, r'HeI', fontsize=20, ha='center') ax.text(HeII, ypos, r'HeII', fontsize=20, ha='center') ax.set_ylim(1e-15, 1e1) ax.set_xlim(100, 1200)
def plot(path, iout, pickle_path, the_mass_bins=[7., 8., 9., 10,], lab='', ax=None, **kwargs): import pickle from seren3.analysis.plots import fit_scatter from seren3.utils import flatten_nested_array import matplotlib.pylab as plt sim = seren3.init(path) # snap = seren3.load_snapshot(path, iout) snap = sim[iout] fname = "%s/sfr_halos_%05i.p" % (pickle_path, iout) data = pickle.load(open(fname, 'rb')) sfr_halos = []; bin_centre_halos = []; Mvir = [] for i in range(len(data)): res = data[i].result sfr_halos.append(res["SFR"].in_units("Msol yr**-1")) bin_centre_halos.append(res["lookback-time"]) Mvir.append(res["Mvir"]) sfr_halos = np.array(sfr_halos); bin_centre_halos = np.array(bin_centre_halos); Mvir = np.array(Mvir) idx = np.where(np.log10(Mvir) >= 6.5) sfr_halos = sfr_halos[idx]; bin_centre_halos = bin_centre_halos[idx]; Mvir = Mvir[idx] # Bin idx mass_bins = np.digitize(np.log10(Mvir), the_mass_bins, right=True) binned_sfr = {} nbins = kwargs.pop("nbins", 100) # nbins = kwargs.pop("nbins", 50) for i in range(len(the_mass_bins)+1): if (i == len(the_mass_bins)): x, y = ( flatten_nested_array(bin_centre_halos), flatten_nested_array(sfr_halos) ) idx = np.where(~np.isnan(y)) binned_sfr["all"] = fit_scatter(x[idx], y[idx], ret_sterr=True, ret_n=True, nbins=nbins) else: idx = np.where( mass_bins == i ) x, y = ( flatten_nested_array(bin_centre_halos[idx]), flatten_nested_array(sfr_halos[idx]) ) idx = np.where(~np.isnan(y)) binned_sfr[i] = fit_scatter(x[idx], y[idx], ret_sterr=True, ret_n=True, nbins=nbins) binned_sfr['the_mass_bins'] = the_mass_bins if ax is None: # return binned_sfr fig, ax = plt.subplots(figsize=(8,8)) # ax = plt.gca() cols = None if "cols" not in kwargs: from seren3.utils import plot_utils cols = plot_utils.ncols(len(the_mass_bins), cmap=kwargs.pop("cmap", "Set1"))[::-1] # cols = plot_utils.ncols(len(the_mass_bins), cmap=kwargs.pop("cmap", "Set1"))[::-1] # cols = ["r", "b", "darkorange", "k"] else: cols = kwargs.pop("cols") ls = kwargs.pop("linestyle", "-") lw = kwargs.get("lw", 2.5) z_fn = sim.redshift_func(zmax=1000., zmin=0.) age_fn = sim.age_func() sim_age = age_fn(snap.z) for i,c in zip(range(len(the_mass_bins)), cols): # for i,c in zip([1, len(the_mass_bins)-1], cols): x,y,std,stderr,n = binned_sfr[i] age = sim_age - x age_to_z = z_fn(age) if i == len(the_mass_bins) - 1: upper = r"$\infty$" else: upper = "%1.1f" % the_mass_bins[i+1] lower = "%1.1f" % the_mass_bins[i] # label = "BC03 log(M) = [%s, %s)" % (lower, upper) label = "%s log(M) = [%s, %s)" % (lab, lower, upper) if kwargs.get("legend", False) is False: label = None # print label, n # ax.errorbar(x, y, yerr=std, label=label, linewidth=3., \ # color=c, linestyle=ls, capsize=5) from scipy import integrate from seren3.array import SimArray integrated_mstar = integrate.trapz(y, SimArray(x, "Gyr").in_units("yr")) print integrated_mstar # ax.step(x, y, label=label, linewidth=2.5, color=c, linestyle=ls) ax.step(age_to_z, y, label=label, linewidth=lw, color=c, linestyle=ls) # ax.set_xlabel(r"Lookback-time [Gyr]") ax.set_xlabel(r"$z$") ax.set_ylabel(r"SFR [M$_{\odot}$ yr$^{-1}$]") if kwargs.pop("legend", False): # Shrink current axis by 20% # box = ax.get_position() # ax.set_position([box.x0, box.y0 + box.height * 0.15, # box.width, box.height * 0.9]) # Put a legend to the right of the current axis # leg = ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.15), # fancybox=True, shadow=False, ncol=6, prop={"size":18}) leg = ax.legend(loc="upper right", prop={"size":14}) # leg.set_title(r"log$_{10}$(Mvir) [M$_{\odot}$/h]", prop = {'size':'x-large'}) # ax.set_ylim(-0.05, 1.05) ax.set_yscale("log") # ax.set_xscale("log") ax.set_ylim(1e-6, 5e0) ax.set_xlim(6., 20.) # ax.set_xlim(0.,) return binned_sfr
def test2(sim_labels, the_mass_bins=[7., 8., 9., 10.], **kwargs): import numpy as np import matplotlib.pylab as plt from seren3.array import SimArray from pymses.utils import constants as C import matplotlib.gridspec as gridspec import seren3 sim1 = seren3.load("RT2_nohm") sim2 = seren3.load("RAMSES") snap1 = sim1[106] snap2 = sim2[93] info = snap1.info cols = None if "cols" not in kwargs: from seren3.utils import plot_utils cols = plot_utils.ncols(len(the_mass_bins), cmap=kwargs.pop("cmap", "Set1"))[::-1] # cols = plot_utils.ncols(2, cmap=kwargs.pop("cmap", "Set1"))[::-1] else: cols = kwargs.pop("cols") z = (1. / info["aexp"]) - 1. fig = plt.figure(figsize=(10, 8)) gs = gridspec.GridSpec(4, 9, wspace=0., hspace=0.) ax1 = fig.add_subplot(gs[1:-1, :4]) ax2 = fig.add_subplot(gs[:1, :4], sharex=ax1) axs = np.array([ax1, ax2]) nbins = 7 ax = ax1 binned_cdf1 = plot(snap1.path, snap1.ioutput, "%s/pickle/" % snap1.path, "nHI", ax=None, nbins=nbins) binned_cdf2 = plot(snap2.path, snap2.ioutput, "%s/pickle/" % snap2.path, "nHI", ax=None, nbins=nbins) text_pos = (7.2, 0.1) text = 'z = %1.2f' % z # ax.text(text_pos[0], text_pos[1], text, color="k", size=18) # for bcdf, ls in zip([binned_cdf1, binned_cdf2], ["-", "--"]): # label = "All" # x,y,std,stderr,n = bcdf["all"] # e = ax.errorbar(x, y, yerr=std, color="k", label=label,\ # fmt="o", markerfacecolor="w", mec='k', capsize=2, capthick=2, elinewidth=2, linestyle=ls, linewidth=2.) for bcdf, ls in zip([binned_cdf1, binned_cdf2], ["-", "--"]): for ibin, c in zip(range(len(the_mass_bins)), cols): # for ibin, c in zip([0, len(the_mass_bins)-1], cols): x, y, std, stderr, n = bcdf[ibin] if ibin == len(the_mass_bins) - 1: upper = r"$\infty$" else: upper = "%i" % the_mass_bins[ibin + 1] lower = "%i" % the_mass_bins[ibin] label = "[%s, %s)" % (lower, upper) if (ls == "--"): label = None upper_err = [] lower_err = [] for i in range(len(y)): ue = 0. le = 0. if (y[i] + std[i] > 1): ue = 1. - y[i] else: ue = std[i] if (y[i] - std[i] < 0): le = y[i] else: le = std[i] upper_err.append(ue) lower_err.append(le) yerr = [lower_err, upper_err] e = ax.errorbar(x, y, yerr=yerr, color=c, label=label,\ fmt="o", markerfacecolor=c, mec='k', capsize=2, capthick=2, elinewidth=2, linestyle=ls, linewidth=2.) for sl, ls in zip(sim_labels, ["-", "--"]): ax.plot([2, 4], [-100, -100], linewidth=2., linestyle=ls, color="k", label=sl) # ax.legend(prop={"size":18}, loc="lower right") ax.set_ylim(-0.05, 1.2) ax = ax2 linestyles = ["-", "--", "-.", ":"] for ibin, c, ls in zip(range(len(the_mass_bins)), cols, linestyles): # for ibin, c, ls in zip([0, len(the_mass_bins)-1], cols, linestyles): x1, y1, std1, stderr1, n1 = binned_cdf1[ibin] x2, y2, std2, stderr2, n2 = binned_cdf2[ibin] # ydiv = y1/y2 ydiv = y1 - y2 # error_prop = np.abs(ydiv) * np.sqrt( (std1/y1)**2 + (std2/y2)**2 ) error_prop = np.sqrt((std1)**2 + (std2)**2) print ibin, error_prop e = ax.errorbar(x1, ydiv, yerr=error_prop, color=c,\ fmt="o", markerfacecolor=c, mec='k', capsize=2, capthick=2, elinewidth=2, linestyle=ls, linewidth=2.) axs[0].set_xlabel(r"log$_{10}$ n$_{\mathrm{HI}}$ [m$^{-3}$]") # axs[0].set_xlabel(r"log$_{10}$ T [K]") axs[0].set_ylabel(r"CDF") axs[1].set_ylabel(r"$\Delta$ CDF") plt.setp(ax2.get_xticklabels(), visible=False) # ax = axs[0] # leg = ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.15), # fancybox=True, shadow=False, ncol=3, prop={"size":18}) # leg.set_title(r"log$_{10}$(Mvir) [M$_{\odot}$/h]", prop = {'size':'x-large'}) n_star = SimArray(info["n_star"].express(C.H_cc), "cm**-3").in_units("m**-3") for axi in axs.flatten(): axi.vlines(np.log10(n_star), -1, 2, color='k', linestyle='-.') # axi.vlines(np.log10(2e4), -5, 5, color='k', linestyle='-.') axs[1].set_ylim(-0.2, 1.3) # axs[1].set_ylim(0.2, -1.3) ################################################################################## ax1 = fig.add_subplot(gs[1:-1, 5:]) ax2 = fig.add_subplot(gs[:1, 5:], sharex=ax1) axs = np.array([ax1, ax2]) ax = ax1 binned_cdf1 = plot(snap1.path, snap1.ioutput, "%s/pickle/" % snap1.path, "T2_minus_Tpoly", ax=None, nbins=nbins) binned_cdf2 = plot(snap2.path, snap2.ioutput, "%s/pickle/" % snap2.path, "T2_minus_Tpoly", ax=None, nbins=nbins) text_pos = (7.2, 0.1) text = 'z = %1.2f' % z # ax.text(text_pos[0], text_pos[1], text, color="k", size=18) # for bcdf, ls in zip([binned_cdf1, binned_cdf2], ["-", "--"]): # label = "All" # x,y,std,stderr,n = bcdf["all"] # e = ax.errorbar(x, y, yerr=std, color="k", label=label,\ # fmt="o", markerfacecolor="w", mec='k', capsize=2, capthick=2, elinewidth=2, linestyle=ls, linewidth=2.) for bcdf, ls in zip([binned_cdf1, binned_cdf2], ["-", "--"]): for ibin, c in zip(range(len(the_mass_bins)), cols): # for ibin, c in zip([0, len(the_mass_bins)-1], cols): x, y, std, stderr, n = bcdf[ibin] if ibin == len(the_mass_bins) - 1: upper = r"$\infty$" else: upper = "%i" % the_mass_bins[ibin + 1] lower = "%i" % the_mass_bins[ibin] label = "[%s, %s)" % (lower, upper) if (ls == "--"): label = None upper_err = [] lower_err = [] for i in range(len(y)): ue = 0. le = 0. if (y[i] + std[i] > 1): ue = 1. - y[i] else: ue = std[i] if (y[i] - std[i] < 0): le = y[i] else: le = std[i] upper_err.append(ue) lower_err.append(le) yerr = [lower_err, upper_err] e = ax.errorbar(x, y, yerr=yerr, color=c, label=label,\ fmt="o", markerfacecolor=c, mec='k', capsize=2, capthick=2, elinewidth=2, linestyle=ls, linewidth=2.) for sl, ls in zip(sim_labels, ["-", "--"]): ax.plot([2, 4], [-100, -100], linewidth=2., linestyle=ls, color="k", label=sl) # ax.legend(prop={"size":18}, loc="lower right") ax.set_ylim(-0.05, 1.2) ax = ax2 linestyles = ["-", "--", "-.", ":"] for ibin, c, ls in zip(range(len(the_mass_bins)), cols, linestyles): # for ibin, c, ls in zip([0, len(the_mass_bins)-1], cols, linestyles): x1, y1, std1, stderr1, n1 = binned_cdf1[ibin] x2, y2, std2, stderr2, n2 = binned_cdf2[ibin] # ydiv = y1/y2 ydiv = y1 - y2 # error_prop = np.abs(ydiv) * np.sqrt( (std1/y1)**2 + (std2/y2)**2 ) error_prop = np.sqrt((std1)**2 + (std2)**2) print ibin, error_prop e = ax.errorbar(x1, ydiv, yerr=error_prop, color=c,\ fmt="o", markerfacecolor=c, mec='k', capsize=2, capthick=2, elinewidth=2, linestyle=ls, linewidth=2.) # axs[0].set_xlabel(r"log$_{10}$ n$_{\mathrm{HI}}$ [m$^{-3}$]") axs[0].set_xlabel(r"log$_{10}$ T - T$_{\mathrm{J}}$ [K/$\mu$]") # axs[0].set_ylabel(r"CDF") # axs[1].set_ylabel(r"$\Delta$ CDF") plt.setp(ax2.get_xticklabels(), visible=False) ax = axs[0] leg = ax.legend(loc='upper center', bbox_to_anchor=(-0.15, -0.2), fancybox=True, shadow=False, ncol=3, prop={"size": 18}) leg.set_title(r"log$_{10}$(Mvir) [M$_{\odot}$/h] : z = %1.2f" % snap1.z, prop={'size': 'x-large'}) n_star = SimArray(info["n_star"].express(C.H_cc), "cm**-3").in_units("m**-3") for axi in axs.flatten(): # axi.vlines(np.log10(n_star), -1, 2, color='k', linestyle='-.') axi.vlines(np.log10(2e4), -5, 5, color='k', linestyle='-.') # axs[1].set_ylim(-0.2, 1.3) axs[1].set_ylim(0.2, -1.3) # plt.yscale("log") # plt.tight_layout() plt.savefig("/home/ds381/rt2_hd_cdf_nHI_T_z6_15.pdf", format="pdf") plt.show()
def test(binned_cdf1, binned_cdf2, info, sim_labels, field, the_mass_bins=[7., 8., 9., 10.], **kwargs): import numpy as np import matplotlib.pylab as plt from seren3.array import SimArray from pymses.utils import constants as C import matplotlib.gridspec as gridspec assert len(binned_cdf1) == len(binned_cdf2) cols = None if "cols" not in kwargs: from seren3.utils import plot_utils cols = plot_utils.ncols(len(the_mass_bins), cmap=kwargs.pop("cmap", "Set1"))[::-1] # cols = ["r", "b", "darkorange", "k"] else: cols = kwargs.pop("cols") z = (1. / info["aexp"]) - 1. fig = plt.figure(figsize=(7, 10)) gs = gridspec.GridSpec(4, 4, wspace=0., hspace=0.) ax1 = fig.add_subplot(gs[1:-1, :]) ax2 = fig.add_subplot(gs[:1, :], sharex=ax1) axs = np.array([ax1, ax2]) ax = ax1 text_pos = (7.2, 0.1) text = 'z = %1.2f' % z ax.text(text_pos[0], text_pos[1], text, color="k", size=18) for bcdf, ls in zip([binned_cdf1, binned_cdf2], ["-", "--"]): for ibin, c in zip(range(len(the_mass_bins)), cols): x, y, std, stderr, n = bcdf[ibin] if ibin == len(the_mass_bins) - 1: upper = r"$\infty$" else: upper = "%i" % the_mass_bins[ibin + 1] lower = "%i" % the_mass_bins[ibin] label = "[%s, %s)" % (lower, upper) if (ls == "--"): label = None e = ax.errorbar(x, y, yerr=std, color=c, label=label,\ fmt="o", markerfacecolor=c, mec='k', capsize=2, capthick=2, elinewidth=2, linestyle=ls, linewidth=2.) for sl, ls in zip(sim_labels, ["-", "--"]): ax.plot([2, 4], [-100, -100], linewidth=2., linestyle=ls, color="k", label=sl) # ax.legend(prop={"size":18}, loc="lower right") ax.set_ylim(-0.05, 1.2) ax = ax2 linestyles = ["-", "--", "-.", ":"] for ibin, c, ls in zip(range(len(the_mass_bins)), cols, linestyles): # for ibin in range(len(the_mass_bins)): x1, y1, std1, stderr1, n1 = binned_cdf1[ibin] x2, y2, std2, stderr2, n2 = binned_cdf2[ibin] # ydiv = y1/y2 ydiv = y1 - y2 # error_prop = np.abs(ydiv) * np.sqrt( (std1/y1)**2 + (std2/y2)**2 ) error_prop = np.sqrt((std1)**2 + (std2)**2) print ibin, error_prop e = ax.errorbar(x1, ydiv, yerr=error_prop, color=c,\ fmt="o", markerfacecolor=c, mec='k', capsize=2, capthick=2, elinewidth=2, linestyle=ls, linewidth=2.) axs[0].set_xlabel(r"log$_{10}$ n$_{\mathrm{HI}}$ [m$^{-3}$]") # axs[0].set_xlabel(r"log$_{10}$ T [K]") axs[0].set_ylabel(r"CDF") axs[1].set_ylabel(r"$\Delta$ CDF") plt.setp(ax2.get_xticklabels(), visible=False) ax = axs[0] leg = ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.15), fancybox=True, shadow=False, ncol=3, prop={"size": 18}) leg.set_title(r"log$_{10}$(Mvir) [M$_{\odot}$/h]", prop={'size': 'x-large'}) n_star = SimArray(info["n_star"].express(C.H_cc), "cm**-3").in_units("m**-3") for axi in axs.flatten(): axi.vlines(np.log10(n_star), -1, 2, color='k', linestyle='-.') # axi.vlines(np.log10(2e4), -5, 5, color='k', linestyle='-.') axs[1].set_ylim(-0.2, 1.3) # axs[1].set_ylim(0.2, -1.3) # plt.yscale("log") plt.tight_layout() plt.savefig("/home/ds381/rt2_hd_cdf_%s_z6_15.pdf" % field, format="pdf") plt.show()