Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update some examples to Plots.jl #46

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions examples/RECFAST_example.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,10 @@ bg = Background(𝕡)
𝕣 = Bolt.RECFAST(bg=bg, Yp=𝕡.Y_p, OmegaB=𝕡.Ω_b) # 𝕣 = Bolt.Peebles()
ih = IonizationHistory(𝕣, 𝕡, bg)

Nz = 1000
dz = 10000/float(Nz)
dz = 10000/1000
z = (10000 - dz):(-dz):0.0
##

using PyPlot
clf()
plot(z, ih.Tmat.(z2x.(z)), "-", label=raw"$T_{\mathrm{mat}}$")
plot(z, ih.Trad.(z2x.(z)), "--", label=raw"$T_{\mathrm{rad}}$")

yscale("log")
xscale("log")
legend()
ylim(1, 2e4)
xlim(10, 10000)
xlabel("redshift")
ylabel("temperature [K]")
gcf()
using Plots, LaTeXStrings
plot(z, ih.Tmat.(z2x.(z)), ls=:solid, label=L"T_{\mathrm{mat}}", xlim=(10,10000),
xscale=:log10, xlabel="redshift", ylabel="temperature [K]", yscale=:log10, legend=:bottomright)
plot!(z, ih.Trad.(z2x.(z)), ls=:dash, label=L"T_{\mathrm{rad}}")
17 changes: 4 additions & 13 deletions examples/plot_recomb.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using Bolt
using PyPlot
using Unitful, UnitfulAstro, NaturallyUnitful

using Plots, LaTeXStrings
par = CosmoParams()

# integrate saha to some transition redshift, we choose 1587.4
Expand All @@ -14,13 +12,6 @@ early_time_Xₑ = Bolt.saha_Xₑ(par)
late_time_Xₑ = Bolt.peebles_Xₑ(
par, early_time_Xₑ(x_transition), x_transition, 1.0)

clf()
plot(saha_z_grid, [early_time_Xₑ(z2x(z)) for z in saha_z_grid], "-", label="Saha")
plot(peebles_z_grid, [late_time_Xₑ(z2x(z)) for z in peebles_z_grid], "-", label="Peebles")
ylabel(raw"$X_e$")
xlim(1800,0)
ylim(2e-4, 2)
yscale("log")
xlabel(raw"$z$")
legend()
gcf()
plot(saha_z_grid, [early_time_Xₑ(z2x(z)) for z in saha_z_grid], label="Saha", xflip=true,
yscale=:log10, xlabel="redshift", ylabel=L"X_e")
plot!(peebles_z_grid, [late_time_Xₑ(z2x(z)) for z in peebles_z_grid], label="Peebles")
27 changes: 8 additions & 19 deletions examples/plot_visibility.jl
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
using Bolt
using PyPlot
using Unitful, UnitfulAstro, NaturallyUnitful
using Interpolations
using Plots, LaTeXStrings

par = CosmoParams()
bg = Background(par)
ih = IonizationHistory(Peebles(), par, bg)
x_grid = bg.x_grid

clf()
fig, ax = subplots(1,2,figsize=(10,5))
ax[1].plot(x_grid, ih.τ.(x_grid), "-", label=raw"$\tau$")
ax[1].plot(x_grid, abs.(ih.τ′.(x_grid)), "--", label=raw"$|\tau^\prime|$")
ax[2].plot(x_grid, ih.g̃.(x_grid), "-", label=raw"$\tilde{g}$")
ax[2].plot(x_grid, ih.g̃′.(x_grid) ./ 10, "--", label=raw"$\tilde{g}\prime/10$")
ax[2].plot(x_grid, ih.g̃′′.(x_grid) ./ 300, "--", label=raw"$\tilde{g}\prime/300$")
ax[1].set_yscale("log")
ax[1].legend()
ax[1].set_xlabel(raw"$x$")
ax[2].set_xlim(-8.0, -6.0)
ax[2].set_ylim(-3.5, 5.5)
ax[2].legend()
ax[2].set_xlabel(raw"$x$")
tight_layout()
gcf()
l = @layout [a ; b]
p1 = plot(x_grid, ih.τ.(x_grid), label=L"\tau", yscale=:log10)
plot!(x_grid, abs.(ih.τ′.(x_grid)), ls=:dash, label=L"|\tau^\prime|")
p2 = plot(x_grid, ih.g̃.(x_grid), label=L"\tilde{g}", xlim=(-8.0, -6.0), xlabel="x")
plot!(x_grid, ih.g̃′.(x_grid) ./ 10, ls=:dash, label=L"\tilde{g}\prime/10")
plot!(x_grid, ih.g̃′′.(x_grid) ./ 300, ls=:dash, label=L"\tilde{g}\prime/300")
plot(p1, p2, layout = l, size=(350,500))