Skip to content

Commit

Permalink
Add Plots extension
Browse files Browse the repository at this point in the history
  • Loading branch information
brenhinkeller committed Dec 8, 2024
1 parent 4b3af40 commit e438cf4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
StatGeochemBase = "61e559cd-58b4-4257-8528-26bb26ff2b9a"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[weakdeps]
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"

[compat]
BangBang = "0.4.3"
Distributions = "0.25"
Expand Down
41 changes: 41 additions & 0 deletions ext/PlotsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module PlotsExt

using Thermochron
using Plots

# Plot chronometers in general
Plots.plot(y::Vector{<:Chronometer}, args...; framestyle=:box, kwargs...) = plot!(plot(), y, args...; framestyle, kwargs...)
Plots.plot(x, y::Vector{<:Chronometer}, args...; framestyle=:box, kwargs...) = plot!(plot(), x, y, args...; framestyle, kwargs...)
Plots.plot(x::Vector{<:Chronometer}, y::Vector{<:Chronometer}, args...; framestyle=:box, kwargs...) = plot!(plot(), x, y, args...; framestyle, kwargs...)
for P in (Plots.Plot, Plots.Subplot)
@eval Plots.plot!(hdl::($P), y::Vector{<:Chronometer}; framestyle=:box, kwargs...) = plot!(hdl, Thermochron.val.(y); yerror=Thermochron.err.(y), framestyle, kwargs...)
@eval Plots.plot!(hdl::($P), x, y::Vector{<:Chronometer}; framestyle=:box, kwargs...) = plot!(hdl, x, Thermochron.val.(y); yerror=Thermochron.err.(y), framestyle, kwargs...)
@eval Plots.plot!(hdl::($P), x::Vector{<:Chronometer}, y; framestyle=:box, kwargs...) = plot!(hdl, Thermochron.val.(x), y; xerror=Thermochron.err.(x), framestyle, kwargs...)
@eval Plots.plot!(hdl::($P), x::Vector{<:Chronometer}, y::Vector{<:Chronometer}; framestyle=:box, kwargs...) = plot!(hdl, Thermochron.val.(x), Thermochron.val.(y); xerror=Thermochron.err.(x), yerror=Thermochron.err.(y), framestyle, kwargs...)
end

# Age-eU plots
Thermochron.ageeu(x::Vector{<:Chronometer}, args...; framestyle=:box, kwargs...) = Thermochron.ageeu!(plot(), x, args..., framestyle, kwargs...)
Thermochron.ageeu!(hdl::Plots.Plot, x::Vector{<:Chronometer}; seriestype=:scatter, mscolor=:auto, kwargs...) = plot!(hdl, eU.(x), Thermochron.val.(x); yerror=Thermochron.err(x), seriestype, mscolor, kwargs...)
Thermochron.ageeu!(hdl::Plots.Subplot, x::Vector{<:Chronometer}; seriestype=:scatter, mscolor=:auto, kwargs...) = plot!(hdl, eU.(x), Thermochron.val.(x); yerror=Thermochron.err(x), seriestype, mscolor, kwargs...)

lowerbound(x::Uniform) = x.a
lowerbound(x::Distribution) = quantile(d, 0.025)
upperbound(x::Uniform) = x.b
upperbound(x::Distribution) = quantile(d, 0.975)

Plots.plot(c::Constraint; framestyle=:box, kwargs...) = plot!(plot(), c; framestyle, kwargs...)
for P in (Plots.Plot, Plots.Subplot)
@eval function Plots.plot!(hdl::($P), c::Constraint; framestyle=:box, kwargs...)
for i in eachindex(c.agedist, c.Tdist)
t, T = c.agedist[i], c.Tdist[i]
x = [lowerbound(t), upperbound(t), upperbound(t), lowerbound(t)]
y = [upperbound(T), upperbound(T), lowerbound(T), lowerbound(T)]
plot!(hdl, Shape(x, y); framestyle, kwargs...)
end
return hdl
end
end


end # module

0 comments on commit e438cf4

Please sign in to comment.