def simple_wcbar(D, x, y, z, s=None, labels=labels, limits=limits, cmap=cm.viridis, add_weighted_median=True): # # # --- if no selection provided select all galaxies # if not s: # s = D[x] == D[x] # --- if no limits provided base limits on selected data ranges for v in [x, y, z]: if v not in limits.keys(): limits[v] = [np.min(D[v][s]), np.max(D[v][s])] # --- if no labels provided just use the name for v in [x, y, z]: if v not in labels.keys(): labels[v] = v # --- get template figure from flare.plt fig, ax, cax = fplt.simple_wcbar() # --- define colour scale norm = mpl.colors.Normalize(vmin=limits[z][0], vmax=limits[z][1]) # --- plot ax.scatter(D[x][s], D[y][s], s=1, alpha=0.5, c=cmap(norm(D[z][s]))) # --- weighted median Lines if add_weighted_median: bins = np.linspace(*limits[x], 20) bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(D[x][s], D[y][s], D['weight'][s], bins, [0.84, 0.50, 0.16]) ax.plot(bincen, out[:, 1], c='k', ls='-') # ax.fill_between(bincen[Ns], out[:,0][Ns], out[:,2][Ns], color='k', alpha = 0.2) ax.set_xlim(limits[x]) ax.set_ylim(limits[y]) ax.set_ylabel(rf'$\rm {labels[y]}$', fontsize=9) ax.set_xlabel(rf'$\rm {labels[x]}$', fontsize=9) # --- add colourbar cmapper = cm.ScalarMappable(norm=norm, cmap=cmap) cmapper.set_array([]) cbar = fig.colorbar(cmapper, cax=cax, orientation='vertical') cbar.set_label(rf'$\rm {labels[z]} $') return fig, ax, cax
def create_EW_plot(x, y, bins, weights, axs, title, color, ii): quantiles = [0.84,0.50,0.16] ok = np.where(10**y>0) out = fl.binned_weighted_quantile(x[ok],y[ok],weights[ok],bins,quantiles) bincen = (bins[1:]+bins[:-1])/2. yy, yy16, yy84 = out[:,1], out[:,0],out[:,2] # axs.fill_between(bincen, yy16, yy84, color=color, alpha=0.3) axs.scatter(bincen, yy, color=color, alpha=1.0/(ii/10 +1), s=100) axs.locator_params(axis='y', nbins=5) axs.set_title(rF"{title}", fontsize=13)
def simple_zevo(Dt, x, y, s=None, labels=labels, limits=limits): """ redshift evolution of a quantity """ z = list(Dt.keys())[-1] # --- if no limits provided base limits on selected data ranges for v in [x, y]: if v not in limits.keys(): limits[v] = [np.min(D[z][v][s[-1]]), np.max(D[z][v][s[-1]])] # --- if no labels provided just use the name for v in [x, y]: if v not in labels.keys(): labels[v] = v # --- get template figure from flare.plt fig, ax = fplt.simple() norm = mpl.colors.Normalize(vmin=5, vmax=10) cmap = cm.plasma for z, D in Dt.items(): c = cmap(norm(z)) bins = np.linspace(*limits[x], 20) bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(D[x][s[z]], D[y][s[z]], D['weight'][s[z]], bins, [0.84, 0.50, 0.16]) N, be = np.histogram(D['log10Mstar_30'][s[z]], bins=bins) # print(len(N), len(out[:,1])) s2 = N > 10 ax.plot(bincen, out[:, 1], c=c, ls=':') ax.plot(bincen[s2], out[:, 1][s2], c=c, ls='-', label=rf'$\rm z={z}$') # ax.fill_between(bincen[Ns], out[:,0][Ns], out[:,2][Ns], color='k', alpha = 0.2) ax.set_xlim(limits[x]) ax.set_ylim(limits[y]) ax.set_ylabel(rf'$\rm {labels[y]}$', fontsize=9) ax.set_xlabel(rf'$\rm {labels[x]}$', fontsize=9) ax.legend(fontsize=7) return fig, ax
def simple(D, x, y, s=None, labels=labels, limits=limits, nbins=nbins, add_weighted_median=True): # --- if no limits provided base limits on selected data ranges for v in [x, y]: if v not in limits.keys(): limits[v] = [np.min(D[v][s]), np.max(D[v][s])] # --- if no labels provided just use the name for v in [x, y]: if v not in labels.keys(): labels[v] = v # --- if no bins provided just use the name for v in [x, y]: if v not in nbins.keys(): nbins[v] = 25 # --- get template figure from flare.plt fig, ax = fplt.simple() # --- plot ax.scatter(D[x][s], D[y][s], s=1, alpha=0.5, c='k') # --- weighted median Lines if add_weighted_median: bins = np.linspace(*limits[x], nbins[x]) bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(D[x][s], D[y][s], D['weight'][s], bins, [0.84, 0.50, 0.16]) ax.plot(bincen, out[:, 1], c='k', ls='-') # ax.fill_between(bincen[Ns], out[:,0][Ns], out[:,2][Ns], color='k', alpha = 0.2) ax.set_xlim(limits[x]) ax.set_ylim(limits[y]) ax.set_ylabel(rf'$\rm {labels[y]}$', fontsize=9) ax.set_xlabel(rf'$\rm {labels[x]}$', fontsize=9) return fig
x += 10 # units are 1E10 M_sol y += 10 # units are 1E10 M_sol # --- simply print the ranges of the quantities print(z) print(np.min(x), np.median(x), np.max(x)) print(np.min(y), np.median(y), np.max(y)) # -- this will calculate the weighted quantiles of the distribution quantiles = [0.84, 0.50, 0.16] # quantiles for range bins = np.arange(9, 11.5, 0.2) # x-coordinate bins, in this case stellar mass bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(x, y, ws, bins, quantiles) # --- plot the median and quantiles for bins with >10 galaxies N, bin_edges = np.histogram(x, bins=bins) Ns = N > 10 ax.plot(bincen, out[:, 1], c=cmap(norm(z)), ls=':') ax.plot(bincen[Ns], out[:, 1][Ns], c=cmap(norm(z)), label=rf'$\rm z={int(z)}$') ax.fill_between(bincen[Ns], out[:, 0][Ns], out[:, 2][Ns], color=cmap(norm(z)), alpha=0.2)
def linear_redshift_density(D, zeds, x, y, s, labels=labels, limits=limits, rows=1): # --- if no limits provided base limits on selected data ranges for v in [x, y]: if v not in limits.keys(): limits[v] = [ np.min(D[zeds[-1]][v][s[zeds[-1]]]), np.max(D[zeds[-1]][v][s[zeds[-1]]]) ] # --- if no labels provided just use the name for v in [x, y]: if v not in labels.keys(): labels[v] = v N = len(zeds) if rows == 1: left = 0.1 top = 0.9 bottom = 0.25 right = 0.9 panel_width = (right - left) / N panel_height = top - bottom fig, axes = plt.subplots(1, N, figsize=(7, 7 / (panel_height / panel_width)), sharey=True) plt.subplots_adjust(left=left, top=top, bottom=bottom, right=right, wspace=0.0, hspace=0.0) if rows == 2: left = 0.1 top = 0.95 bottom = 0.1 right = 0.9 panel_width = (right - left) / int(N / 2) panel_height = top - bottom fig, axes = plt.subplots(2, int(N / 2), figsize=(7, rows * 7 / (panel_height / panel_width)), sharey=True, sharex=True) plt.subplots_adjust(left=left, top=top, bottom=bottom, right=right, wspace=0.0, hspace=0.1) axes = axes.flatten() ldelta_bins = np.linspace(-0.25, 0.25, 6) norm = mpl.colors.Normalize(vmin=-0.3, vmax=0.3) cmap = cm.Spectral_r for ax, z in zip(axes, zeds): for ldelta in ldelta_bins: sd = s[z] & (np.fabs(D[z]['ldelta'] - ldelta) < 0.05) # --- weighted median Lines bins = np.linspace(*limits[x], 20) bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(D[z][x][sd], D[z][y][sd], D[z]['weight'][sd], bins, [0.84, 0.50, 0.16]) # ax.plot(bincen, out[:,1], c=cmap(norm(ldelta)), ls = '-', label = rf'$\rm {ldelta-0.05:.2f}<\log_{{10}}(1+\delta)<{ldelta+0.05:.2f}$') ax.plot(bincen, out[:, 1], c=cmap(norm(ldelta)), ls='-', label=rf'$\rm [{ldelta-0.05:.2f},{ldelta+0.05:.2f})$') # ax.fill_between(bincen[Ns], out[:,0][Ns], out[:,2][Ns], color='k', alpha = 0.2) ax.set_xlim(limits[x]) ax.set_ylim(limits[y]) if rows == 1: ax.text(0.5, 1.02, rf'$\rm z={z}$', horizontalalignment='center', verticalalignment='bottom', transform=ax.transAxes, fontsize=7) if rows == 2: ax.text(0.5, 1.01, rf'$\rm z={z}$', horizontalalignment='center', verticalalignment='bottom', transform=ax.transAxes, fontsize=8) axes[0].legend(title=r'$\rm \log_{{10}}(1+\delta)$', title_fontsize=6, fontsize=5, labelspacing=0.0) axes[0].set_ylabel(rf'$\rm {labels[y]}$', fontsize=9) if rows == 2: axes[3].set_ylabel(rf'$\rm {labels[y]}$', fontsize=9) fig.text(left + (right - left) / 2, 0.04, rf'$\rm {labels[x]}$', ha='center', fontsize=9) return fig
def linear_redshift(D, zeds, x, y, s, labels=labels, limits=limits, nbins=nbins, scatter=True, scatter_colour_quantity=False, scatter_cmap=None, bins=50, rows=1, add_weighted_median=True, add_weighted_range=False): # --- if no limits provided base limits on selected data ranges for v in [x, y]: if v not in limits.keys(): limits[v] = [ np.min(D[zeds[-1]][v][s[zeds[-1]]]), np.max(D[zeds[-1]][v][s[zeds[-1]]]) ] # --- if no labels provided just use the name for v in [x, y]: if v not in labels.keys(): labels[v] = v # --- if no bins provided just use the name for v in [x, y]: if v not in nbins.keys(): nbins[v] = 25 if scatter_colour_quantity: norm = mpl.colors.Normalize(vmin=limits[scatter_colour_quantity][0], vmax=limits[scatter_colour_quantity][1]) cmap = scatter_cmap N = len(zeds) if rows == 1: left = 0.1 top = 0.9 bottom = 0.25 right = 0.9 panel_width = (right - left) / N panel_height = top - bottom fig, axes = plt.subplots(1, N, figsize=(7, 7 / (panel_height / panel_width)), sharey=True) plt.subplots_adjust(left=left, top=top, bottom=bottom, right=right, wspace=0.0, hspace=0.0) if rows == 2: left = 0.1 top = 0.95 bottom = 0.1 right = 0.9 panel_width = (right - left) / int(N / 2) panel_height = top - bottom fig, axes = plt.subplots(2, int(N / 2), figsize=(7, rows * 7 / (panel_height / panel_width)), sharey=True, sharex=True) plt.subplots_adjust(left=left, top=top, bottom=bottom, right=right, wspace=0.0, hspace=0.1) axes = axes.flatten() for ax, z in zip(axes, zeds): # --- scatter plot here if scatter: if scatter_colour_quantity: ax.scatter(D[z][x][s[z]], D[z][y][s[z]], s=1, alpha=0.5, c=cmap(norm(D[z][scatter_colour_quantity][s[z]]))) else: ax.scatter(D[z][x][s[z]], D[z][y][s[z]], s=1, alpha=0.5, c='k') # --- weighted median Lines if add_weighted_median: bins = np.linspace(*limits[x], nbins[x]) bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(D[z][x][s[z]], D[z][y][s[z]], D[z]['weight'][s[z]], bins, [0.84, 0.50, 0.16]) N, bin_edges = np.histogram(D[z][x][s[z]], bins=bins) i = np.array(range(len(N))) ss = i[N < 1] if len(ss) > 0: sN = i[i < ss[0]] else: sN = i ax.plot(bincen[sN], out[:, 1][sN], c='k', ls='--') ss = i[N < 10] if len(ss) > 0: sN = i[i < ss[0]] else: sN = i ax.plot(bincen[sN], out[:, 1][sN], c='k', ls='-') if add_weighted_range: ax.fill_between(bincen[sN], out[:, 0][sN], out[:, 2][sN], color='k', alpha=0.2) ax.set_xlim(limits[x]) ax.set_ylim(limits[y]) if rows == 1: ax.text(0.5, 1.02, rf'$\rm z={z}$', horizontalalignment='center', verticalalignment='bottom', transform=ax.transAxes, fontsize=7) if rows == 2: ax.text(0.5, 1.01, rf'$\rm z={z}$', horizontalalignment='center', verticalalignment='bottom', transform=ax.transAxes, fontsize=8) axes[0].set_ylabel(rf'$\rm {labels[y]}$', fontsize=9) if rows == 2: axes[3].set_ylabel(rf'$\rm {labels[y]}$', fontsize=9) # --- add colourbar if scatter_colour_quantity: cmapper = cm.ScalarMappable(norm=norm, cmap=cmap) cmapper.set_array([]) cax = fig.add_axes([right, bottom, 0.015, top - bottom]) fig.colorbar(cmapper, cax=cax, orientation='vertical') cax.set_ylabel(rf'$\rm {labels[scatter_colour_quantity]} $', fontsize=7) if rows == 2: cax.set_ylabel(rf'$\rm {labels[scatter_colour_quantity]} $', fontsize=8) cax.tick_params(axis='y', labelsize=6) fig.text(left + (right - left) / 2, 0.04, rf'$\rm {labels[x]}$', ha='center', fontsize=9) return fig, axes
def linear_mcol(D, diagnostics, properties, s, labels=labels, limits=limits, scatter_colour_quantity=False, scatter_cmap=None, bins=50, full_width=True): # --- if no limits provided base limits on selected data ranges for v in properties: if v not in limits.keys(): limits[v] = [np.min(D[v][s]), np.max(D[v][s])] # --- if no labels provided just use the name for v in properties: if v not in labels.keys(): labels[v] = v if scatter_colour_quantity: norm = mpl.colors.Normalize(vmin=limits[scatter_colour_quantity][0], vmax=limits[scatter_colour_quantity][1]) cmap = scatter_cmap Ny = len(diagnostics) Nx = len(properties) if full_width: left = 0.1 top = 0.9 bottom = 0.1 right = 0.9 else: left = 0.15 top = 0.95 bottom = 0.125 right = 0.85 panel_width = (right - left) / Nx panel_height = (top - bottom) / Ny if full_width: fig, axes = plt.subplots(Ny, Nx, figsize=(7, 7 / (panel_height / panel_width)), sharey='row') else: fig, axes = plt.subplots(Ny, Nx, figsize=(3.5, 3.5 / (panel_height / panel_width)), sharey='row') plt.subplots_adjust(left=left, top=top, bottom=bottom, right=right, wspace=0.0, hspace=0.0) for j, y in enumerate(diagnostics): for i, x in enumerate(properties): ax = axes[j, i] # --- scatter plot here if scatter_colour_quantity: ax.scatter(D[x][s], D[y][s], s=1, alpha=0.5, c=cmap(norm(D[scatter_colour_quantity][s]))) else: ax.scatter(D[x][s], D[y][s], s=1, alpha=0.5, c='k') # --- weighted median Lines bins = np.linspace(*limits[x], 20) bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(D[x][s], D[y][s], D['weight'][s], bins, [0.84, 0.50, 0.16]) ax.plot(bincen, out[:, 1], c='k', ls='-') # ax.fill_between(bincen[Ns], out[:,0][Ns], out[:,2][Ns], color='k', alpha = 0.2) ax.set_xlim(limits[x]) ax.set_ylim(limits[y]) ax.set_xlabel(rf'$\rm {labels[x]}$', fontsize=8) if i == 0: ax.set_ylabel(rf'$\rm {labels[y]}$', fontsize=8) # axes[0].set_ylabel(rf'$\rm {labels[y]}$', fontsize = 8) # --- add colourbar if scatter_colour_quantity: cmapper = cm.ScalarMappable(norm=norm, cmap=cmap) cmapper.set_array([]) cax = fig.add_axes([right, bottom, 0.015, top - bottom]) fig.colorbar(cmapper, cax=cax, orientation='vertical') cax.set_ylabel(rf'$\rm {labels[scatter_colour_quantity]} $', fontsize=7) cax.tick_params(axis='y', labelsize=6) return fig
def Lagn_FUV_Mstar(): import matplotlib as mpl import matplotlib.cm as cm mpl.use('Agg') import matplotlib.pyplot as plt import numpy as np import flares linecolor = "#ff6700" zeds = ("5.0", "6.0", "7.0", "8.0", "9.0", "10.0") for z in zeds: Mstar = Data[z]["Mstar"] AGN_FUV = Data[z]["AGN_FUV"] ws = Data[z]["Weights"] quantiles = [0.84, 0.50, 0.16] # quantiles for range bins = np.arange(7.9, 12, 0.2) # x-coordinate bins, in this case stellar mass bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(Mstar, AGN_FUV, ws, bins, quantiles) N, bin_edges = np.histogram(Mstar, bins=bins) Ns = N > 10 plt.figure(figsize=(14, 8)) plt.scatter(Mstar, AGN_FUV, alpha=0.25) plt.plot(bincen, out[:, 1], c=linecolor, ls=':') plt.plot(bincen[Ns], out[:, 1][Ns], c=linecolor, label=r'Weighted median') plt.fill_between(bincen[Ns], out[:, 0][Ns], out[:, 2][Ns], color=linecolor, alpha=0.2) plt.title("z=" + str(z)) plt.xlabel(r"log$_{10}$(M$_{\star}$/M$_\odot$)") plt.ylabel(r"log$_{10}$(L$_{AGN,FUV}$/erg s$^{-1}$ Hz$^{-1}$)") #plt.ylim(14.2, 31.6) plt.xlim(8) plt.grid() plt.legend(loc="lower right") plt.savefig(f"Plots/Lagn_FUV_Mstar/Lagn_FUV_Mstar" + str(int(float(z))) + ".png") plt.clf() fig = plt.figure(figsize=(14, 6)) plot_no = 1 for z in zeds: Mstar = Data[z]["Mstar"] AGN_FUV = Data[z]["AGN_FUV"] ws = Data[z]["Weights"] quantiles = [0.84, 0.50, 0.16] # quantiles for range bins = np.arange(7.9, 12, 0.2) # x-coordinate bins, in this case stellar mass bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(Mstar, AGN_FUV, ws, bins, quantiles) N, bin_edges = np.histogram(Mstar, bins=bins) Ns = N > 10 figloc = '23' + str(plot_no) ax = fig.add_subplot(figloc) ax.scatter(Mstar, AGN_FUV, alpha=0.25) ax.plot(bincen, out[:, 1], c=linecolor, ls=':') ax.plot(bincen[Ns], out[:, 1][Ns], c=linecolor, label=r'Weighted median') ax.fill_between(bincen[Ns], out[:, 0][Ns], out[:, 2][Ns], color=linecolor, alpha=0.2) ax.set_title('z = ' + str(z)) ax.set_xlabel(r"log$_{10}$(M$_{\star}$/M$_\odot$)") ax.set_ylabel(r"log$_{10}$(L$_{AGN,FUV}$/erg s$^{-1}$ Hz$^{-1}$)") ax.grid() ax.legend(loc="lower right") ax.set_ylim(10, 32) ax.set_xlim(8, 12) plot_no += 1 plt.tight_layout(pad=0.5, w_pad=1, h_pad=0.5) fig.savefig(f"Plots/Lagn_FUV_Mstar/Lagn_FUV_Mstar_grid.png") plt.clf() fig.clf() fig = plt.figure(figsize=(14, 6)) plot_no = 1 for z in zeds: Mstar = Data[z]["Mstar"] AGN_FUV = Data[z]["AGN_FUV"] ws = Data[z]["Weights"] quantiles = [0.84, 0.50, 0.16] # quantiles for range bins = np.arange(7.9, 12, 0.2) # x-coordinate bins, in this case stellar mass bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(Mstar, AGN_FUV, ws, bins, quantiles) N, bin_edges = np.histogram(Mstar, bins=bins) Ns = N > 10 figloc = '23' + str(plot_no) ax = fig.add_subplot(figloc) ax.scatter(Mstar, AGN_FUV, alpha=0.25) ax.plot(bincen, out[:, 1], c=linecolor, ls=':') ax.plot(bincen[Ns], out[:, 1][Ns], c=linecolor, label=r'Weighted median') ax.fill_between(bincen[Ns], out[:, 0][Ns], out[:, 2][Ns], color=linecolor, alpha=0.2) ax.set_title('z = ' + str(z)) ax.set_xlabel(r"log$_{10}$(M$_{\star}$/M$_\odot$)") ax.set_ylabel(r"log$_{10}$(L$_{AGN,FUV}$/erg s$^{-1}$ Hz$^{-1}$)") ax.grid() plt.legend(loc="lower right") ax.set_ylim(28, 32) ax.set_xlim(8, 12) plot_no += 1 plt.tight_layout(pad=0.5, w_pad=1, h_pad=0.5) fig.savefig(f"Plots/Lagn_FUV_Mstar/Lagn_FUV_Mstar_grid_zoom.png") plt.clf() fig.clf()
def corner3(D, properties, s, cmaps, labels=labels, limits=limits, bins=50, full_width=True): # --- if no limits provided base limits on selected data ranges for v in properties: if v not in limits.keys(): limits[v] = [np.min(D[v][s]), np.max(D[v][s])] # --- if no labels provided just use the name for v in properties: if v not in labels.keys(): labels[v] = v N = len(properties) - 1 if full_width: left = 0.1 right = 0.9 bottom = 0.1 top = 0.9 fig, axes = plt.subplots(N, N, figsize=(7, 7)) else: left = 0.15 right = 0.95 bottom = 0.1 top = 0.9 fig, axes = plt.subplots(N, N, figsize=(3.5, 3.5)) plt.subplots_adjust(left=left, top=top, bottom=bottom, right=right, wspace=0.0, hspace=0.0) for i in np.arange(N): for j in np.arange(N): axes[i, j].set_axis_off() for i, x in enumerate(properties[:-1]): for j, y in enumerate(properties[1:][::-1]): jj = N - 1 - j ii = i ax = axes[jj, ii] if j + i < N: ax.set_axis_on() z = list(set(properties) ^ set([x, y]))[0] norm = mpl.colors.Normalize(vmin=limits[z][0], vmax=limits[z][1]) cmap = cmaps[z] # --- scatter plot here ax.scatter(D[x][s], D[y][s], s=1, alpha=0.5, c=cmap(norm(D[z][s]))) # --- weighted median Lines bins = np.linspace(*limits[x], 20) bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(D[x][s], D[y][s], D['weight'][s], bins, [0.84, 0.50, 0.16]) ax.plot(bincen, out[:, 1], c='k', ls='-') # ax.fill_between(bincen[Ns], out[:,0][Ns], out[:,2][Ns], color='k', alpha = 0.2) # ax.text(0.5, 0.5, f'{ii}_{jj}',transform=ax.transAxes) ax.set_xlim(limits[x]) ax.set_ylim(limits[y]) if i == 0: # first column ax.set_ylabel(rf'$\rm {labels[y]}$', fontsize=7) else: ax.yaxis.set_ticklabels([]) if j == 0: # first row ax.set_xlabel(rf'$\rm {labels[x]}$', fontsize=7) else: ax.xaxis.set_ticklabels([]) # ax.text(0.5, 0.5, f'x{i}-y{j}', transform = ax.transAxes) # --- add colourbar for i, z in enumerate(properties): norm = mpl.colors.Normalize(vmin=limits[z][0], vmax=limits[z][1]) cmap = cmaps[z] cmapper = cm.ScalarMappable(norm=norm, cmap=cmap) cmapper.set_array([]) width = right - left height = top - bottom cax = fig.add_axes([ left + width / 2 + 0.025, bottom + height / 2 + i * width / (2 * len(properties)) + 0.025, width / 2 - 0.025, 0.015 ]) fig.colorbar(cmapper, cax=cax, orientation='horizontal') cax.set_xlabel(rf'$\rm {labels[z]} $', fontsize=6) cax.xaxis.tick_top() cax.xaxis.set_label_position('top') cax.tick_params(axis='x', labelsize=5) return fig, axes
yerr=[ np.log10(yy[nonzero]) - np.log10(yy[nonzero] - yyerr[nonzero]), np.log10(yy[nonzero] + yyerr[nonzero]) - np.log10(yy[nonzero]) ], color=s_m.to_rgba( (dbins[kk] + dbins[kk + 1]) / 2)) elif input == plt_options[1]: LFUV_this = np.concatenate(LFUV[ok]) LFUV_int_this = np.concatenate(LFUV_int[ok]) y = -2.5 * np.log10(LFUV_this / LFUV_int_this) x = lum_to_M(LFUV_this) quantiles = [0.84, 0.50, 0.16] out = fl.binned_weighted_quantile(x, y, np.ones(len(x)), bins, quantiles) hist, binedges = np.histogram(x, bins) tok = np.where(hist > 0)[0] axs[ii].errorbar(bincen[tok], out[:, 1][tok], lw=2, ls='solid', marker='o', yerr=[ out[:, 1][tok] - out[:, 2][tok], out[:, 0][tok] - out[:, 1][tok] ], color=s_m.to_rgba( (dbins[kk] + dbins[kk + 1]) / 2)) axs[ii].set_xlim((-16.9, -24.7))
def linear_redshift_mcol(D, zeds, x, properties, s, labels=labels, limits=limits, scatter_colour_quantity=False, scatter_cmap=None, bins=50, add_linear_fit=False, height=1): # --- if no limits provided base limits on selected data ranges for v in [x] + properties: if v not in limits.keys(): limits[v] = [ np.min(D[zeds[-1]][v][s[zeds[-1]]]), np.max(D[zeds[-1]][v][s[zeds[-1]]]) ] # --- if no labels provided just use the name for v in [x] + properties: if v not in labels.keys(): labels[v] = v if scatter_colour_quantity: norm = mpl.colors.Normalize(vmin=limits[scatter_colour_quantity][0], vmax=limits[scatter_colour_quantity][1]) cmap = scatter_cmap Np = len(properties) N = len(zeds) left = 0.1 top = 0.9 bottom = 0.15 #somewhat dependent on Np right = 0.9 panel_width = (right - left) / N panel_height = (top - bottom) / Np fig, axes = plt.subplots(Np, N, figsize=(7, height * 7 / (panel_height / panel_width)), sharex=True, sharey='row') plt.subplots_adjust(left=left, top=top, bottom=bottom, right=right, wspace=0.0, hspace=0.0) for j, y in enumerate(properties): for i, z in enumerate(zeds): ax = axes[j, i] # --- scatter plot here if scatter_colour_quantity: ax.scatter(D[z][x][s[z]], D[z][y][s[z]], s=1, alpha=0.5, c=cmap(norm(D[z][scatter_colour_quantity][s[z]]))) else: ax.scatter(D[z][x][s[z]], D[z][y][s[z]], s=1, alpha=0.5, c='k') # --- weighted median Lines bins = np.linspace(*limits[x], 20) bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(D[z][x][s[z]], D[z][y][s[z]], D[z]['weight'][s[z]], bins, [0.84, 0.50, 0.16]) ax.plot(bincen, out[:, 1], c='k', ls='-') # ax.fill_between(bincen[Ns], out[:,0][Ns], out[:,2][Ns], color='k', alpha = 0.2) # --- linear first if add_linear_fit: # fit_p = np.polyfit(D[z][x][s[z]],D[z][y][s[z]], 1, w = D[z]['weight'][s[z]]) x_ = D[z][x][s[z]] y_ = D[z][y][s[z]] w_ = D[z]['weight'][s[z]] s_ = (~np.isnan(x_)) & (~np.isnan(y_)) & (~np.isinf(y_) ) # capture NaNs fit_p = np.polyfit(x_[s_], y_[s_], 1, w=w_[s_]) fit = lambda x: fit_p[1] + fit_p[0] * x ax.plot(limits[x], fit(np.array(limits[x])), lw=1, c='k', ls='--') ax.set_xlim(limits[x]) ax.set_ylim(limits[y]) axes[j, 0].set_ylabel(rf'$\rm {labels[y]}$', fontsize=9) for i, z in enumerate(zeds): axes[0, i].text(0.5, 1.02, rf'$\rm z={z}$', horizontalalignment='center', verticalalignment='bottom', transform=axes[0, i].transAxes, fontsize=7) # --- add colourbar if scatter_colour_quantity: cmapper = cm.ScalarMappable(norm=norm, cmap=cmap) cmapper.set_array([]) cax = fig.add_axes([right, bottom, 0.015, top - bottom]) fig.colorbar(cmapper, cax=cax, orientation='vertical') cax.set_ylabel(rf'$\rm {labels[scatter_colour_quantity]} $', fontsize=7) cax.tick_params(axis='y', labelsize=6) fig.text(left + (right - left) / 2, 0.04, rf'$\rm {labels[x]}$', ha='center', fontsize=9) return fig, axes
def corner_whist(D, properties, s, labels=labels, limits=limits, scatter_colour_quantity=False, scatter_cmap=None, bins=50): # --- if no limits provided base limits on selected data ranges for v in properties: if v not in limits.keys(): limits[v] = [np.min(D[v][s]), np.max(D[v][s])] # --- if no labels provided just use the name for v in properties: if v not in labels.keys(): labels[v] = v if scatter_colour_quantity: norm = mpl.colors.Normalize(vmin=limits[scatter_colour_quantity][0], vmax=limits[scatter_colour_quantity][1]) cmap = scatter_cmap N = len(properties) fig, axes = plt.subplots(N, N, figsize=(7, 7)) plt.subplots_adjust(left=0.1, top=0.9, bottom=0.1, right=0.9, wspace=0.02, hspace=0.02) for i in np.arange(N): for j in np.arange(N): axes[i, j].set_axis_off() for i, x in enumerate(properties): for j, y in enumerate(properties[1:][::-1]): jj = N - 1 - j ii = i ax = axes[jj, ii] if j + i < (N - 1): ax.set_axis_on() # --- scatter plot here if scatter_colour_quantity: ax.scatter(D[x][s], D[y][s], s=1, alpha=0.5, c=cmap(norm(D[scatter_colour_quantity][s]))) else: ax.scatter(D[x][s], D[y][s], s=1, alpha=0.5, c='k') # --- weighted median Lines bins = np.linspace(*limits[x], 20) bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(D[x][s], D[y][s], D['weight'][s], bins, [0.84, 0.50, 0.16]) ax.plot(bincen, out[:, 1], c='k', ls='-') # ax.fill_between(bincen[Ns], out[:,0][Ns], out[:,2][Ns], color='k', alpha = 0.2) ax.set_xlim(limits[x]) ax.set_ylim(limits[y]) if i == 0: # first column ax.set_ylabel(rf'$\rm {labels[y]}$', fontsize=7) else: ax.yaxis.set_ticklabels([]) if j == 0: # first row ax.set_xlabel(rf'$\rm {labels[x]}$', fontsize=7) else: ax.xaxis.set_ticklabels([]) # ax.text(0.5, 0.5, f'x{i}-y{j}', transform = ax.transAxes) # --- histograms ax = axes[ii, ii] ax.set_axis_on() ax.spines['top'].set_visible(False) ax.spines['right'].set_visible(False) ax.spines['bottom'].set_visible(False) ax.spines['left'].set_visible(False) ax.get_xaxis().set_ticks([]) ax.get_yaxis().set_ticks([]) X = D[x][s] H, bin_edges = np.histogram(X, bins=bins, range=limits[x]) Hw, bin_edges = np.histogram(X, bins=bins, range=limits[x], weights=D['weight'][s]) Hw *= np.max(H) / np.max(Hw) bin_centres = bin_edges[:-1] + (bin_edges[1] - bin_edges[0]) * 0.5 ax.fill_between(bin_centres, H * 0.0, H, color='0.9') ax.plot(bin_centres, Hw, c='0.7', lw=1) ax.set_ylim([0.0, np.max(H) * 1.2]) # --- add colourbar if scatter_colour_quantity: cmapper = cm.ScalarMappable(norm=norm, cmap=cmap) cmapper.set_array([]) cax = fig.add_axes([0.25, 0.87, 0.5, 0.015]) fig.colorbar(cmapper, cax=cax, orientation='horizontal') cax.set_xlabel(rf'$\rm {labels[scatter_colour_quantity]} $') return fig
if j + i < (N - 1): ax.set_axis_on() # --- scatter plot here ax.scatter(D[x][s], D[y][s], s=1, alpha=0.5, c=cmap(norm(D['log10Mstar_30'][s]))) # --- weighted median Lines bins = np.linspace(*limits[x], 20) bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(D[x][s], D[y][s], ws[s], bins, [0.84, 0.50, 0.16]) ax.plot(bincen, out[:, 1], c='k', ls='-') # ax.fill_between(bincen[Ns], out[:,0][Ns], out[:,2][Ns], color='k', alpha = 0.2) ax.set_xlim(limits[x]) ax.set_ylim(limits[y]) if i == 0: # first column ax.set_ylabel(rf'$\rm {labels[y]}$', fontsize=7) else: ax.yaxis.set_ticklabels([]) if j == 0: # first row ax.set_xlabel(rf'$\rm {labels[x]}$', fontsize=7) else:
h = 0.6777 vol = (4 / 3) * np.pi * (14 / h) ** 3 phi = N_weighted / (binw * vol) phi_nonhost = N_weighted_nonhost / (binw * vol) axes.flatten()[i].plot(bins[:-1] + binw / 2, np.log10(phi), c=cmap(norm(z))) axes.flatten()[i].plot(bins[:-1] + binw / 2, np.log10(phi_nonhost), '--', c=cmap(norm(z))) ''' # -- this will calculate the weighted quantiles of the distribution quantiles = [0.84, 0.50, 0.16] # quantiles for range bins = np.arange(7, 11, 0.1) # x-coordinate bins bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(x, y, ws, bins, quantiles) out_nonhost = flares.binned_weighted_quantile(x_nonhost, y_nonhost, ws_nonhost, bins, quantiles) # --- plot the median and quantiles for bins with >10 galaxies N, bin_edges = np.histogram(x, bins=bins) Ns = N > 10 axes.flatten()[i].plot(bincen, out[:, 1], c=cmap(norm(z)), ls=':') axes.flatten()[i].plot(bincen[Ns], out[:, 1][Ns], c=cmap(norm(z))) axes.flatten()[i].fill_between(bincen[Ns], out[:, 0][Ns], out[:, 2][Ns], color=cmap(norm(z)), alpha=0.2)
def FUV_ratio_MBH(): import matplotlib as mpl import matplotlib.cm as cm mpl.use('Agg') import matplotlib.pyplot as plt import numpy as np import flares linecolor = "#800080" zeds = ("5.0", "6.0", "7.0", "8.0", "9.0", "10.0") for z in zeds: Gal_FUV = Data[z]["Gal_FUV"] AGN_FUV = Data[z]["AGN_FUV"] MBH = Data[z]["MBH"] x = np.linspace(5, max(MBH) + 0.5) y = np.zeros(len(x)) Ratio = np.zeros(len(Gal_FUV)) for i in range(len(Ratio)): Ratio[i] = AGN_FUV[i] - Gal_FUV[i] ws = Data[z]["Weights"] quantiles = [0.84, 0.50, 0.16] # quantiles for range bins = np.arange(4.8, 12, 0.2) # x-coordinate bins, in this case stellar mass bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(MBH, Ratio, ws, bins, quantiles) N, bin_edges = np.histogram(MBH, bins=bins) Ns = N > 10 plt.figure(figsize=(14, 8)) plt.scatter(MBH, Ratio, alpha=0.25) plt.plot(x, y, "k--") plt.plot(bincen, out[:, 1], c=linecolor, ls=':') plt.plot(bincen[Ns], out[:, 1][Ns], c=linecolor, label=r'Weighted median') plt.fill_between(bincen[Ns], out[:, 0][Ns], out[:, 2][Ns], color=linecolor, alpha=0.2) plt.title("z=" + str(z)) plt.xlabel(r"log$_{10}$(M$_{BH}$/M$_\odot$)") plt.ylabel(r"log$_{10}$(L$_{AGN,FUV}$/L$_{Gal,FUV}$)") #plt.ylim(14.2, 31.6) plt.xlim(5.16, max(x)) plt.grid() plt.legend(loc="lower right") plt.savefig(f"Plots/FUV_ratio_MBH/FUV_ratio_MBH_" + str(int(float(z))) + ".png") plt.clf() fig = plt.figure(figsize=(14, 6)) plot_no = 1 for z in zeds: Gal_FUV = Data[z]["Gal_FUV"] AGN_FUV = Data[z]["AGN_FUV"] MBH = Data[z]["MBH"] Ratio = np.zeros(len(Gal_FUV)) for i in range(len(Ratio)): Ratio[i] = AGN_FUV[i] - Gal_FUV[i] x = np.linspace(5, 12) y = np.zeros(len(x)) ws = Data[z]["Weights"] quantiles = [0.84, 0.50, 0.16] # quantiles for range bins = np.arange(4.8, 12, 0.2) # x-coordinate bins, in this case stellar mass bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(MBH, Ratio, ws, bins, quantiles) N, bin_edges = np.histogram(MBH, bins=bins) Ns = N > 10 figloc = '23' + str(plot_no) ax = fig.add_subplot(figloc) ax.scatter(MBH, Ratio, alpha=0.25) ax.plot(x, y, "k--") ax.plot(bincen, out[:, 1], c=linecolor, ls=':') ax.plot(bincen[Ns], out[:, 1][Ns], c=linecolor, label=r'Weighted median') ax.fill_between(bincen[Ns], out[:, 0][Ns], out[:, 2][Ns], color=linecolor, alpha=0.2) ax.set_title('z = ' + str(z)) ax.set_xlabel(r"log$_{10}$(M$_{BH}$/M$_\odot$)") ax.set_ylabel(r"log$_{10}$(L$_{AGN,FUV}$/L$_{Gal,FUV}$)") ax.grid() ax.legend(loc="lower right") ax.set_ylim(-17, 2) ax.set_xlim(5.16, 9.5) plot_no += 1 plt.tight_layout(pad=0.5, w_pad=1, h_pad=0.5) fig.savefig(f"Plots/FUV_ratio_MBH/FUV_ratio_MBH_grid.png") plt.clf() fig.clf() fig = plt.figure(figsize=(14, 6)) plot_no = 1 for z in zeds: Gal_FUV = Data[z]["Gal_FUV"] AGN_FUV = Data[z]["AGN_FUV"] MBH = Data[z]["MBH"] Ratio = np.zeros(len(Gal_FUV)) for i in range(len(Ratio)): Ratio[i] = AGN_FUV[i] - Gal_FUV[i] x = np.linspace(5, 12) y = np.zeros(len(x)) ws = Data[z]["Weights"] quantiles = [0.84, 0.50, 0.16] # quantiles for range bins = np.arange(4.8, 12, 0.2) # x-coordinate bins, in this case stellar mass bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(MBH, Ratio, ws, bins, quantiles) N, bin_edges = np.histogram(MBH, bins=bins) Ns = N > 10 figloc = '23' + str(plot_no) ax = fig.add_subplot(figloc) ax.scatter(MBH, Ratio, alpha=0.25) ax.plot(x, y, "k--") ax.plot(bincen, out[:, 1], c=linecolor, ls=':') ax.plot(bincen[Ns], out[:, 1][Ns], c=linecolor, label=r'Weighted median') ax.fill_between(bincen[Ns], out[:, 0][Ns], out[:, 2][Ns], color=linecolor, alpha=0.2) ax.set_title('z = ' + str(z)) ax.set_xlabel(r"log$_{10}$(M$_{BH}$/M$_\odot$)") ax.set_ylabel(r"log$_{10}$(L$_{AGN,FUV}$/L$_{Gal,FUV}$)") ax.grid() ax.legend(loc="upper left") ax.set_ylim(-1, 2) ax.set_xlim(5.16, 9.5) plot_no += 1 plt.tight_layout(pad=0.5, w_pad=1, h_pad=0.5) fig.savefig(f"Plots/FUV_ratio_MBH/FUV_ratio_MBH_grid_zoom.png") plt.clf() fig.clf()
axs[ii].hexbin(x, y, C=z, gridsize=gridsize, cmap=plt.cm.get_cmap('coolwarm'), mincnt=1, extent=extent, alpha=1, reduce_C_function=np.median, vmin=-2.4, vmax=-1.1) bincen = (bins[1:] + bins[:-1]) / 2. binwidth = bins[1:] - bins[:-1] quantiles = [0.84, 0.50, 0.16] out = fl.binned_weighted_quantile(x, y, w, bins, quantiles) hist, binedges = np.histogram(x, bins) ok = np.where(hist > 0)[0] ok1 = np.where(hist[ok] > 3)[0][0] axs[ii].fill_between(bincen[ok][ok1:], out[:, 0][ok][ok1:], out[:, 2][ok][ok1:], color='black', alpha=0.2) axs[ii].plot(bincen[ok][ok1:], out[:, 1][ok][ok1:], ls='-', color='black', alpha=.5, lw=2) axs[ii].plot(bincen[ok],
def simple_wcbar_whist(D, x, y, z, s=None, labels=labels, limits=limits, cmap=cm.viridis, add_weighted_median=True, base_size=3.5): left = 0.15 height = 0.70 bottom = 0.15 width = 0.6 hwidth = 0.15 fig = plt.figure(figsize=(base_size, base_size * width / height)) ax = fig.add_axes((left, bottom, width, height)) hax = fig.add_axes([left + width, bottom, hwidth, height]) cax = fig.add_axes([left, bottom + height, width, 0.03]) # # # --- if no selection provided select all galaxies # if not s: # s = D[x] == D[x] # --- if no limits provided base limits on selected data ranges for v in [x, y, z]: if v not in limits.keys(): limits[v] = [np.min(D[v][s]), np.max(D[v][s])] # --- if no labels provided just use the name for v in [x, y, z]: if v not in labels.keys(): labels[v] = v # --- define colour scale norm = mpl.colors.Normalize(vmin=limits[z][0], vmax=limits[z][1]) # --- plot ax.scatter(D[x][s], D[y][s], s=1, alpha=0.5, c=cmap(norm(D[z][s]))) # --- add histogram bins = np.linspace(*limits[y], 20) bincen = (bins[:-1] + bins[1:]) / 2. H, bin_edges = np.histogram(D[y][s], bins=bins, range=limits[x], density=True) Hw, bin_edges = np.histogram(D[y][s], bins=bins, range=limits[x], weights=D['weight'][s], density=True) X = [] Y = [] bef = 0.0 for i, be in enumerate(bin_edges[:-1]): X.append(be) Y.append(bef) X.append(be) Y.append(Hw[i]) bef = Hw[i] hax.plot(Y, X, c='k', ls='-', lw=1) # hax.plot(H, bincen, c='k', ls = ':', lw=1) # hax.plot(H, bincen, c='k', ls = ':', lw=1) # hax.plot(Hw, bincen, c='k', ls = '-', lw=1) hax.set_xlim([0, 1.2 * np.max(Y)]) hax.set_xticks([]) hax.set_yticks([]) # ax.fill_between(bincen[Ns], out[:,0][Ns], out[:,2][Ns], color='k', alpha = 0.2) # --- weighted median Lines if add_weighted_median: bins = np.linspace(*limits[x], 20) bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(D[x][s], D[y][s], D['weight'][s], bins, [0.84, 0.50, 0.16]) ax.plot(bincen, out[:, 1], c='k', ls='-') # ax.fill_between(bincen[Ns], out[:,0][Ns], out[:,2][Ns], color='k', alpha = 0.2) ax.set_xlim(limits[x]) ax.set_ylim(limits[y]) ax.set_ylabel(rf'$\rm {labels[y]}$', fontsize=9) ax.set_xlabel(rf'$\rm {labels[x]}$', fontsize=9) # --- add colourbar cmapper = cm.ScalarMappable(norm=norm, cmap=cmap) cmapper.set_array([]) cbar = fig.colorbar(cmapper, cax=cax, orientation='horizontal') cbar.set_label(rf'$\rm {labels[z]} $') cbar.ax.xaxis.set_ticks_position('top') cbar.ax.xaxis.set_label_position('top') return fig, ax, cax, hax
for ii, tag in enumerate(tags): z = float(tag[5:].replace('p','.')) mstar = get_data_all(tag, inp = 'FLARES', DF = False) ws = np.array([]) for jj in sims: ws = np.append(ws, np.ones(np.shape(mstar[jj]))*weights[jj]) mstar = np.log10(np.concatenate(mstar)*1e10) data = get_Z(tag) S_met = np.log10(np.concatenate(data[:,0])) G_met = np.log10(np.concatenate(data[:,1])) out = flares.binned_weighted_quantile(mstar, G_met,ws,bins,quantiles) xx, yy, yy84, yy16 = bincen, out[:,1], out[:,0],out[:,2] hist, edges=np.histogram(mstar, bins) ok = np.where(hist>=5)[0] ax.errorbar(xx[ok], yy[ok], ls='-', color=s_m.to_rgba(ii+0.5), alpha=.9, lw=1, fmt='s') yerr1_lo = np.append(yerr1_lo, np.max(yy[ok]-yy16[ok])) yerr1_up = np.append(yerr1_up, np.max(yy84[ok]-yy[ok])) out = flares.binned_weighted_quantile(mstar, S_met,ws,bins,quantiles) xx, yy, yy84, yy16 = bincen, out[:,1], out[:,0],out[:,2] ax.errorbar(xx[ok], yy[ok], ls='-', color=s_m.to_rgba(ii+0.5), alpha=0.35, lw=2, fmt='D') yerr2_lo = np.append(yerr2_lo, np.max(yy[ok]-yy16[ok])) yerr2_up = np.append(yerr2_up, np.max(yy84[ok]-yy[ok]))
def Lagn_FUV_Lgal_FUV(): import matplotlib as mpl import matplotlib.cm as cm mpl.use('Agg') import matplotlib.pyplot as plt import numpy as np import flares zeds = ("5.0", "6.0", "7.0", "8.0", "9.0", "10.0") for z in zeds: Gal_FUV = Data[z]["Gal_FUV"] AGN_FUV = Data[z]["AGN_FUV"] ws = Data[z]["Weights"] linecolor = "#00008b" quantiles = [0.84, 0.50, 0.16] # quantiles for range bins = np.arange(27.9, 31.3, 0.2) # x-coordinate bins, in this case stellar mass bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(Gal_FUV, AGN_FUV, ws, bins, quantiles) N, bin_edges = np.histogram(Gal_FUV, bins=bins) Ns = N > 10 x = np.linspace(0, 35) plt.figure(figsize=(14, 8)) plt.scatter(Gal_FUV, AGN_FUV, alpha=0.25) plt.plot(x, x, "k--", label=r"L$_{AGN,FUV}$ = L$_{Gal,FUV}$") plt.plot(bincen, out[:, 1], c=linecolor, ls=':') plt.plot(bincen[Ns], out[:, 1][Ns], c=linecolor, label=r'Weighted median') plt.fill_between(bincen[Ns], out[:, 0][Ns], out[:, 2][Ns], color=linecolor, alpha=0.2) plt.legend(loc="lower right") plt.title("z=" + str(z)) plt.xlabel(r"log$_{10}$(L$_{Gal,FUV}$/erg s$^{-1}$ Hz$^{-1}$)") plt.ylabel(r"log$_{10}$(L$_{AGN,FUV}$/erg s$^{-1}$ Hz$^{-1}$)") plt.ylim(min(AGN_FUV) - 0.5, max(AGN_FUV) + 0.5) plt.xlim(28, max(Gal_FUV) + 0.5) plt.grid() plt.savefig(f"Plots/Lfuv_AGN_GAL/Lfuv_AGN_GAL_" + str(int(float(z))) + ".png") plt.clf() fig = plt.figure(figsize=(14, 6)) plot_no = 1 for z in zeds: Gal_FUV = Data[z]["Gal_FUV"] AGN_FUV = Data[z]["AGN_FUV"] ws = Data[z]["Weights"] linecolor = "#00008b" quantiles = [0.84, 0.50, 0.16] # quantiles for range bins = np.arange(27.9, 31.3, 0.2) # x-coordinate bins, in this case stellar mass bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(Gal_FUV, AGN_FUV, ws, bins, quantiles) N, bin_edges = np.histogram(Gal_FUV, bins=bins) Ns = N > 10 x = np.linspace(0, 35) figloc = '23' + str(plot_no) ax = fig.add_subplot(figloc) ax.scatter(Gal_FUV, AGN_FUV, alpha=0.25) ax.plot(x, x, "k--", label=r"L$_{AGN,FUV}$ = L$_{Gal,FUV}$") ax.plot(bincen, out[:, 1], c=linecolor, ls=':') ax.plot(bincen[Ns], out[:, 1][Ns], c=linecolor, label=r'Weighted median') ax.fill_between(bincen[Ns], out[:, 0][Ns], out[:, 2][Ns], color=linecolor, alpha=0.2) ax.legend(loc="lower right") ax.set_title('z = ' + str(z)) ax.set_xlabel(r"log$_{10}$(L$_{Gal,FUV}$/erg s$^{-1}$ Hz$^{-1}$)") ax.set_ylabel(r"log$_{10}$(L$_{AGN,FUV}$/erg s$^{-1}$ Hz$^{-1}$)") ax.grid() ax.set_ylim(8, 31.6) ax.set_xlim(28, 31.6) plot_no += 1 x = np.linspace(0, 35) plt.tight_layout(pad=0.5, w_pad=1, h_pad=0.5) fig.savefig(f"Plots/Lfuv_AGN_GAL/Lfuv_AGN_GAL_grid.png") plt.clf() fig.clf() fig = plt.figure(figsize=(14, 6)) plot_no = 1 for z in zeds: Gal_FUV = Data[z]["Gal_FUV"] AGN_FUV = Data[z]["AGN_FUV"] x = np.linspace(0, 35) ws = Data[z]["Weights"] linecolor = "#00008b" quantiles = [0.84, 0.50, 0.16] # quantiles for range bins = np.arange(27.9, 31.3, 0.2) # x-coordinate bins, in this case stellar mass bincen = (bins[:-1] + bins[1:]) / 2. out = flares.binned_weighted_quantile(Gal_FUV, AGN_FUV, ws, bins, quantiles) N, bin_edges = np.histogram(Gal_FUV, bins=bins) Ns = N > 10 figloc = '23' + str(plot_no) ax = fig.add_subplot(figloc) ax.scatter(Gal_FUV, AGN_FUV, alpha=0.25) ax.plot(x, x, "k--", label=r"L$_{AGN,FUV}$ = L$_{Gal,FUV}$") ax.plot(bincen, out[:, 1], c=linecolor, ls=':') ax.plot(bincen[Ns], out[:, 1][Ns], c=linecolor, label=r'Weighted median') ax.fill_between(bincen[Ns], out[:, 0][Ns], out[:, 2][Ns], color=linecolor, alpha=0.2) ax.set_title('z = ' + str(z)) ax.set_xlabel(r"log$_{10}$(L$_{Gal,FUV}$/erg s$^{-1}$ Hz$^{-1}$)") ax.set_ylabel(r"log$_{10}$(L$_{AGN,FUV}$/erg s$^{-1}$ Hz$^{-1}$)") ax.legend(loc="lower right") ax.grid() ax.set_ylim(28, 31.6) ax.set_xlim(28, 31.2) plot_no += 1 plt.tight_layout(pad=0.5, w_pad=1, h_pad=0.5) fig.savefig(f"Plots/Lfuv_AGN_GAL/Lfuv_AGN_GAL_grid_zoom.png") plt.clf() fig.clf()