Skip to content

Commit

Permalink
png output
Browse files Browse the repository at this point in the history
  • Loading branch information
sosiristseng committed Dec 14, 2023
1 parent eaa11b2 commit f1cf584
Show file tree
Hide file tree
Showing 28 changed files with 222 additions and 22 deletions.
5 changes: 5 additions & 0 deletions docs/figs/ch1-07.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ using SimpleUnPack
using Plots
Plots.default(linewidth=2)

# PNG output in Literate.jl
PNG(fig) = display("image/png", fig)

# Convenience functions
hil(x, k) = x / (x + k)
hil(x, k, n) = hil(x^n, k^n)
Expand Down Expand Up @@ -49,3 +52,5 @@ prob = ODEProblem(collins!, u0, tend, ps)
sol = solve(prob, callback=events)

fig = plot(sol, legend=:right, xlabel = "Time", ylabel="Concentration", title="Fig 1.7")

fig |> PNG
5 changes: 5 additions & 0 deletions docs/figs/ch1-09.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ using SimpleUnPack
using Plots
Plots.default(linewidth=2)

# PNG output in Literate.jl
PNG(fig) = display("image/png", fig)

# Convenience functions
hil(x, k) = x / (x + k)
hil(x, k, n) = hil(x^n, k^n)
Expand Down Expand Up @@ -64,3 +67,5 @@ p1 = plot(sol, idxs=[:v], ylabel="Membrane potential (mV)", xlabel="", legend=fa
p2 = plot(sol, idxs = [:m, :h, :n], xlabel="")
p3 = plot(_istim, sol.t, xlabel="Time (ms)", ylabel="Current", labels="Stimulation current")
fig = plot(p1, p2, p3, layout=(3, 1), size=(600, 900), leftmargin=5*Plots.mm)

fig |> PNG
6 changes: 5 additions & 1 deletion docs/figs/ch2-04.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ Exponential decay
using Plots
Plots.default(linewidth=2)

# PNG output in Literate.jl
PNG(fig) = display("image/png", fig)

#---
fig = plot(title= "Fig 2.4")
for k in 1:3
plot!(fig, t -> 3 * exp(-k*t), 0., 5., label = "exp(-$(k)t)")
end

plot!(fig, xlim = (0, 5), ylim=(0, 3.2), xlabel="Time", ylabel="Concentration")
plot!(fig, xlim = (0, 5), ylim=(0, 3.2), xlabel="Time", ylabel="Concentration") |> PNG
2 changes: 2 additions & 0 deletions docs/figs/ch2-09.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ fig = plot(sol, legend=:bottomright, title="Fig 2.9",
xlims=(0., 4.), ylims=(0., 1.),
xlabel="Time (sec)", ylabel="Concentration (mM)"
)

fig |> PNG
13 changes: 12 additions & 1 deletion docs/figs/ch2-11.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ using ModelingToolkit
using Plots
Plots.default(linewidth=2)

# PNG output in Literate.jl
PNG(fig) = display("image/png", fig)

#---

rn211 = @reaction_network begin
k0, 0 --> A
(k1, km1), A <--> B
Expand All @@ -29,7 +34,7 @@ fig = plot(
xlabel="Time (AU)",
ylabel="Concentration (AU)",
title="Fig. 2.11 (Full model)"
)
) |> PNG


# ## Figure 2.12 : Rapid equilibrium assumption
Expand Down Expand Up @@ -80,6 +85,8 @@ plot!(fig,
ylabel="Concentration (AU)"
)

fig |> PNG

#===
## Figure 2.13: Rapid equilibrium (take 2)
Expand All @@ -101,6 +108,8 @@ plot!(fig,
ylabel="Concentration (AU)"
)

fig |> PNG


#===
## Figure 2.14 : QSSA
Expand Down Expand Up @@ -136,3 +145,5 @@ plot!(fig,
title="Figure 2.14: Ref vs QSSA",
xlims=(0.0, tend)
)

fig |> PNG
6 changes: 6 additions & 0 deletions docs/figs/ch2-p246.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ using DifferentialEquations
using Plots
Plots.default(linewidth=2)

# PNG output in Literate.jl
PNG(fig) = display("image/png", fig)

#---
fig = ODEProblem((u, p, t) -> p * (1. - u), 0., 10., 1.) |> solve |> plot

fig |> PNG
7 changes: 7 additions & 0 deletions docs/figs/ch3-03.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ using Catalyst
using Plots
Plots.default(linewidth=2)

# PNG output in Literate.jl
PNG(fig) = display("image/png", fig)

# Reaction neetwork
rn = @reaction_network begin
(k1, km1), S + E <--> ES
Expand Down Expand Up @@ -42,6 +45,8 @@ sol = solve(prob)
@unpack S, ES, E, P = osys
fig = plot(sol, idxs=[S, ES, E, P], xlabel="Time (AU)", ylabel="Concentration (AU)", legend=:right, title="Fig 3.03")

fig |> PNG

#---
rn303mm = @reaction_network begin
mm(S, k2 * ET, (km1 + k2) / k1), S P ## using \Rightarrow
Expand Down Expand Up @@ -72,3 +77,5 @@ plot!(fig, title="Fig. 3.03",
xlabel="Time (AU)", ylabel="Concentration (AU)",
xlims=(0., tend), ylims=(0., 5.), legend=:right
)

fig |> PNG
6 changes: 6 additions & 0 deletions docs/figs/ch3-13.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Generalized mass action (GMA) vs. Michaelis-Menten rate laws
using Plots
Plots.default(linewidth=2)

# PNG output in Literate.jl
PNG(fig) = display("image/png", fig)

#---
mm = t -> 2t / (1+t)
gma = t -> t^0.4

Expand All @@ -16,3 +20,5 @@ fig = plot(
xlabel= "Substrate concentration (AU)",
ylabel="Reaction rate (AU)"
)

fig |> PNG
18 changes: 17 additions & 1 deletion docs/figs/ch4-01.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ using SimpleUnPack
using Plots
Plots.default(linewidth=2)

# Convenience functions
# PNG output in Literate.jl
PNG(fig) = display("image/png", fig)

# Convenience functions
hil(x, k) = x / (x + k)
hil(x, k, n) = hil(x^n, k^n)

Expand Down Expand Up @@ -54,6 +56,8 @@ sols = [solve(ODEProblem(model41!, u0, tend, ps1)) for u0 in u0s];
#---
fig = plot(sols[1], xlabel="Time", ylabel="Concentration", title="Fig. 4.2 A (Time series)", labels=["[A]" "[B]"])

fig |> PNG

# ## Fig. 4.2 B (Phase plot)

fig = plot( sols[1], idxs=(:a, :b),
Expand All @@ -63,6 +67,8 @@ fig = plot( sols[1], idxs=(:a, :b),
ylims=(0.0, 2.0), xlims=(0.0, 2.0)
)

fig |> PNG

# ## Fig. 4.3 A (Multiple time series)

fig = plot(title="Fig. 4.3A (Multiple time series)")
Expand All @@ -73,6 +79,8 @@ end

plot!(fig, xlabel="Time", ylabel="Concentration")

fig |> PNG

# ## Fig. 4.3 B (Phase plot)

fig = plot(title="Fig. 4.3 B (Phase plot)")
Expand All @@ -83,6 +91,8 @@ end

plot!(fig, xlabel="[A]", ylabel="[B]", xlims=(0., 2.), ylims=(0., 2.), aspect_ratio=:equal)

fig |> PNG

# Let's sketch vector fields in phase plots.
∂A = function (x, y)
∂A41((x, y), ps1, 0.0)
Expand Down Expand Up @@ -115,6 +125,8 @@ end

plot!(fig, size=(600, 600), xlims=(rxy[1], rxy[end]), ylims=(rxy[1], rxy[end]), xlabel="[A]", ylabel="[B]")

fig |> PNG

# ## Figure 4.5A

fig = plot(title="Fig. 4.5 A (Phase plot with nullclines)")
Expand All @@ -131,6 +143,8 @@ contour!(fig, 0:0.01:2, 0:0.01:2, ∂B, levels=[0], cbar=false, line=(:black, :d
plot!(fig, Float64[], Float64[], line=(:black, :dash), label="B nullcline") ## Adding a fake line for the legend of B nullcline
plot!(fig, xlim=(0., 2.), ylim=(0., 2.), legend=:bottomright, size=(600, 600), xlabel="[A]", ylabel="[B]", aspect_ratio=:equal)

fig |> PNG

# ## Figure 4.5 B

## Vector field
Expand All @@ -143,3 +157,5 @@ plot!(fig, Float64[], Float64[], line=(:black), label="A nullcline") ## Adding
contour!(fig, 0:0.01:2, 0:0.01:2, ∂B, levels=[0], cbar=false, line=(:black, :dash))
plot!(fig, Float64[], Float64[], line=(:black, :dash), label="B nullcline") ## Adding a fake line for the legend of B nullcline
plot!(fig, xlim=(0., 2.), ylim=(0., 2.), legend=:bottomright, size=(600, 600), xlabel="[A]", ylabel="[B]")

fig |> PNG
15 changes: 15 additions & 0 deletions docs/figs/ch4-07.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ using SimpleUnPack
using Plots
Plots.default(linewidth=2)

# PNG output in Literate.jl
PNG(fig) = display("image/png", fig)

# Convenience functions
hil(x, k) = x / (x + k)
hil(x, k, n) = hil(x^n, k^n)
Expand Down Expand Up @@ -46,6 +49,8 @@ ax1 = plot(sol1, xlabel="Time", ylabel="Concentration", legend=:right, title= "F
ax2 = plot(sol2, xlabel="Time", ylabel="Concentration", legend=:right, title= "Fig 4.7A (2)")
fig = plot(ax1, ax2, layout=(2, 1), size=(600, 600))

fig |> PNG

# ## Fig 4.7 B

∂F47 = function (x, y; scale=20)
Expand Down Expand Up @@ -77,6 +82,8 @@ contour!(fig, 0:0.01:5, 0:0.01:5, ∂B, levels=[0], cbar=false, line=(:black, :d
plot!(fig, Float64[], Float64[], line=(:black, :dash), label="B nullcline")
plot!(fig, xlim=(0, 5), ylim=(0, 5), legend=:topright, size=(600, 600), xlabel="[A]", ylabel="[B]")

fig |> PNG

#===
## Fig 4.8
Expand All @@ -93,6 +100,8 @@ ax1 = plot(sol1, xlabel="Time", ylabel="Concentration", legend=:right, title= "F
ax2 = plot(sol2, xlabel="Time", ylabel="Concentration", legend=:right, title= "Fig 4.8A (2)")
fig = plot(ax1, ax2, layout=(2, 1), size=(600, 600))

fig |> PNG

#---
∂F48 = function (x, y; scale=20)
da = ∂A47((x, y), ps2, 0.0)
Expand All @@ -119,6 +128,8 @@ contour!(fig, 0:0.01:5, 0:0.01:5, ∂B, levels=[0], cbar=false, line=(:black, :d
plot!(fig, Float64[], Float64[], line=(:black, :dash), label="B nullcline")
plot!(fig, xlim=(0, 5), ylim=(0, 5), legend=:topright, size=(600, 600), xlabel="[A]", ylabel="[B]")

fig |> PNG

#===
## Fig 4.8 C
around the unstable steady-state
Expand All @@ -137,6 +148,8 @@ contour!(fig, 1:0.01:1.5, 1:0.01:1.5, ∂B, levels=[0], cbar=false, line=(:black
plot!(fig, Float64[], Float64[], line=(:black, :dash), label="B nullcline")
plot!(fig, xlim=(1, 1.5), ylim=(1, 1.5), legend=:topright, size=(600, 600), xlabel="[A]", ylabel="[B]")

fig |> PNG

# Another way to draw nullclines is to find the analytical solution when dA (or dB) is zero. And then sketch the nullclines in a parameteric plot.

nca47(b, p) = p.k1 / p.k3 * hil(1, b, p.n1)
Expand All @@ -151,3 +164,5 @@ pls = map((8.0, 16.0, 20.0, 35.0)) do k1
end

fig = plot(pls..., size = (800, 800))

fig |> PNG
6 changes: 6 additions & 0 deletions docs/figs/ch4-11.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Surface plots reference: [surface plots @ PlotsGallery.jl](https://goropikari.gi
using Plots
Plots.default(linewidth=2)

# PNG output in Literate.jl
PNG(fig) = display("image/png", fig)

#---
z1(x, y) = x^2 + 0.5y^2
z2(x, y) = (.2x^2-1)^2 + y^2
x1 = y1 = range(-1.0, 1.0, 41)
Expand All @@ -18,3 +22,5 @@ p3 = surface(x2, y2, z2, title="Double-well potential")
p4 = contourf(x2, y2, z2)

fig = plot(p1, p2, p3, p4, size=(800, 600))

fig |> PNG
13 changes: 13 additions & 0 deletions docs/figs/ch4-15.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ using SimpleUnPack
using Plots
Plots.default(linewidth=2)

# PNG output in Literate.jl
PNG(fig) = display("image/png", fig)

#---

function dA415(u, p, t)
Expand Down Expand Up @@ -48,6 +51,8 @@ end

fig = plot(sols[1], xlabel="Time", ylabel="Concentration", title ="Fig 4.15 (A)", xlims=(0., 8.))

fig |> PNG

# ## Fig 4.15 (B)

∂F415 = function (x, y; scale=20)
Expand Down Expand Up @@ -82,6 +87,8 @@ for sol in sols
end
plot!(fig, xlim=(0, 4), ylim=(0, 4), legend=:topright, size=(600, 600), xlabel="[A]", ylabel="[B]")

fig |> PNG

#===
## Fig 4.16 A
Expand All @@ -103,6 +110,8 @@ end;

fig = plot(sols[1], xlabel="Time", ylabel="Concentration", title ="Fig 4.16(A)", xlims=(0., 8.))

fig |> PNG

# ## Fig 4.16 b
∂F416 = function (x, y; scale=20)
da = dA415((x, y), ps2, 0.0)
Expand Down Expand Up @@ -135,6 +144,8 @@ for sol in sols
end
plot!(fig, xlim=(0, 4), ylim=(0, 4), legend=:topright, size=(600, 600), xlabel="[A]", ylabel="[B]")

fig |> PNG

# ## Fig 4.17

sol = solve(ODEProblem(model415!, LVector(a=2.0, b=1.5), 10.0, ps2))
Expand All @@ -147,3 +158,5 @@ plot!(fig, identity, 0, 0, line=(:black), label="A nullcline")
contour!(fig, 1:0.01:3, 1:0.01:3, ∂B, levels=[0], cbar=false, line=(:black, :dash))
plot!(fig, identity, 0, 0, line=(:black, :dash), label="B nullcline")
plot!(fig, xlims=(1, 3), ylims=(1, 3), legend=:topright, size=(600, 600), xlabel="[A]", ylabel="[B]")

fig |> PNG
5 changes: 5 additions & 0 deletions docs/figs/ch4-18.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ using LabelledArrays
using Plots
Plots.default(linewidth=2)

# PNG output in Literate.jl
PNG(fig) = display("image/png", fig)

#---
hil(x, k) = x / (x + k)
hil(x, k, n) = hil(x^n, k^n)
Expand Down Expand Up @@ -39,3 +42,5 @@ fig = plot(
xlabel = "K1" , ylabel= "Steady state [A]",
legend=nothing, ylim=(0, 4), xlim=(0, 1000)
)

fig |> PNG
5 changes: 5 additions & 0 deletions docs/figs/ch4-22.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ using ForwardDiff
using Plots
Plots.default(linewidth=2)

# PNG output in Literate.jl
PNG(fig) = display("image/png", fig)

# The curve
f = x -> 3 / (x-2)

Expand All @@ -26,3 +29,5 @@ plot!(fig, g, 2.7, 5.3, lab="Tangent line")
plot!(fig, xlabel="Reaction rate", ylabel="Inhibitor concentration",
xlims=(2., 8.), ylims=(0., 4.)
)

fig |> PNG
Loading

0 comments on commit f1cf584

Please sign in to comment.