In [197]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
In [260]:
dat_path = "sfr_release.dat"
zp1, logm, logsfr, logsm = np.loadtxt(dat_path, unpack=True)
z = zp1-1. # Redshift
m = 10.**logm # Mass [Msun]
sfr = 10.**logsfr # Star formation rate [Msun/yr]
zp1, logm, logsfr, logsm = None, None, None, None # clear variables for memory
cut = m>1e10
z = z[cut]
m = m[cut]
sfr = sfr[cut]
# Reshape arrays
z = np.unique(z) # 1D redshift array
m = np.unique(m) # 1D mass array
sfr = np.reshape(sfr, (m.size, z.size)) # 2D SFR array
# Grid arrays
mm, zz = np.meshgrid(m, z, indexing='ij')
logmm = np.log10(mm)
In [265]:
fig = plt.figure(figsize=(10,10))
ax = plt.subplot(111, projection='3d')
xlo, xhi = np.min(logmm), np.max(logmm)
ylo, yhi = np.min(zz), np.max(zz)
#zlo, zhi = np.min(np.log10(sfr[sfr>0])), np.max(np.log10(sfr[sfr>0]))
zlo, zhi = -1., np.max(np.log10(sfr[sfr>0]))
zoff = -3.
cmap = plt.cm.gnuplot
norm = mpl.colors.Normalize(vmin=zlo, vmax=zhi)
ax.contourf(logmm, zz, np.log10(sfr),
vmin=zlo, vmax=zhi,
cmap=cmap, zdir='z', offset=zlo+zoff, antialiased=False, levels=np.linspace(zlo, zhi, 50), extend='min')
ax.plot_surface(logmm, zz, np.where(sfr>0, np.log10(sfr), np.inf),
rstride=2, cstride=2,
vmin=zlo, vmax=zhi,
cmap=cmap, edgecolor='none', shade=True, alpha=0.5)
ax.plot_wireframe(logmm, zz, np.log10(sfr),
rstride=10, cstride=10,
edgecolor='0.25', alpha=1)
# Colorbar - FIGURE THIS OUT LATER
#axcb = fig.add_axes((0.75, 0.75, 0.03, 0.12))
#cb = mpl.colorbar.ColorbarBase(axcb, cmap=cmap, norm=norm, extend='neither', ticks=np.linspace(-1.,3,3))
#axcb.hlines([0,0.5,1], 0, 2, color='g', lw=2, transform=ax.transAxes)
#axcb.text(0.5, 0.5, "hello")
ax.set_xlabel("log(M$_{halo}$) [M$_\odot$]")
ax.set_ylabel("Redshift")
ax.set_zlabel("log(SFR) [M$_\odot$ yr$^{-1}$]")
ax.set_xlim(xlo, xhi)
ax.set_ylim(ylo, yhi)
ax.set_zlim(zlo+zoff, zhi)
ax.view_init(25, -125)
plotdir = "/nfs/slac/g/ki/ki03/tonyyli/plots/intensity_mapping_co/sfr_bwc2013"
plotbase = "sfr_bwc_2013_3d"
plt.savefig("%s/%s.png" % (plotdir, plotbase), bbox_inches='tight')
plt.savefig("%s/%s.pdf" % (plotdir, plotbase), bbox_inches='tight')
plt.savefig("%s/%s.eps" % (plotdir, plotbase), bbox_inches='tight')
#plt.tight_layout()
In [86]:
fig = plt.figure(figsize=(16,12))
ax = plt.subplot(111)
nz = z.size
nskip = 10
for i, redshift in enumerate(z):
if i%nskip==0:
ax.plot(m, sfr[:,i], label="z=%.2f" % (redshift), color=(float(i)/nz,0,0))
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel("Halo mass [M$_\odot$]")
ax.legend()
Out[86]:
In [ ]: