Skip to content

Commit

Permalink
better Makie plotting: consistency and new options
Browse files Browse the repository at this point in the history
Now, point conversion also uses quantiles by default (as rangebars and band did).

Added options to request pmean + pstd plotting instead of pquantiles.
  • Loading branch information
aplavin committed Aug 9, 2024
1 parent e5eabd3 commit 0e29d67
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
27 changes: 22 additions & 5 deletions ext/MakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,28 @@ using MonteCarloMeasurements
Makie.used_attributes(::Type{<:Series}, ::AbstractVector, ::AbstractVector{<:Particles}) = (:N,)
Makie.used_attributes(::Type{<:Series}, ::AbstractVector{<:Tuple{<:Real,<:Particles}}) = (:N,)
Makie.convert_arguments(ct::Type{<:Series}, x::AbstractVector, y::AbstractVector{<:Particles}; N=7) = convert_arguments(ct, x, Matrix(y)[1:min(N, end), :])
Makie.used_attributes(::Type{<:Union{Rangebars,Band}}, ::AbstractVector, ::AbstractVector{<:Particles}) = (:q,)
Makie.used_attributes(::Type{<:Union{Rangebars,Band}}, ::AbstractVector{<:Tuple{<:Real,<:Particles}}) = (:q,)
Makie.convert_arguments(p::Type{<:Union{Hist,Density}}, x::Particles) = convert_arguments(p, Vector(x))
Makie.convert_arguments(ct::Type{<:Union{Rangebars,Band}}, x::AbstractVector, y::AbstractVector{<:Particles}; q=0.16) = convert_arguments(ct, x, pquantile.(y, q), pquantile.(y, 1-q))

Makie.used_attributes(::Type{<:Union{Rangebars,Band}}, ::AbstractVector, ::AbstractVector{<:Particles}) = (:q, :nσ)
Makie.used_attributes(::Type{<:Union{Rangebars,Band}}, ::AbstractVector{<:Tuple{<:Real,<:Particles}}) = (:q, :nσ)
function Makie.convert_arguments(ct::Type{<:Union{Rangebars,Band}}, x::AbstractVector, y::AbstractVector{<:Particles}; q=nothing, nσ=nothing)
!isnothing(q) && !isnothing(nσ) && throw(ArgumentError("Only one of `q`` or `nσ`` can be specified"))
if isnothing(q) && isnothing(nσ)
q = 0.16
end
if !isnothing(q)
convert_arguments(ct, x, pquantile.(y, q), pquantile.(y, 1-q))
elseif !isnothing(nσ)
avgs = pmean.(y)
Δs =.* pstd.(y)
convert_arguments(ct, x, avgs .- Δs, avgs .+ Δs)
end
end

Makie.used_attributes(::PointBased, ::AbstractVector{<:Tuple{<:Real,<:Particles}}) = (:avgfunc,)
Makie.convert_arguments(ct::PointBased, x::AbstractVector{<:Real}, y::AbstractVector{<:Particles}; avgfunc=pmedian) = convert_arguments(ct, x, avgfunc.(y))

Makie.convert_arguments(ct::Type{<:AbstractPlot}, X::AbstractVector{<:Tuple{<:Real,<:Particles}}; kwargs...) = convert_arguments(ct, first.(X), last.(X); kwargs...)
Makie.convert_arguments(ct::PointBased, x::AbstractVector{<:Real}, y::AbstractVector{<:Particles}) = convert_arguments(ct, x, pmean.(y))

Makie.convert_arguments(p::Type{<:Union{Hist,Density}}, x::Particles) = convert_arguments(p, Vector(x))

end
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -666,9 +666,12 @@ Random.seed!(0)

Makie.scatter(xs, ys)
Makie.scatter(tuple.(xs, ys))
Makie.scatter(tuple.(xs, ys), avgfunc=pmean)
Makie.band(xs, ys)
Makie.band(tuple.(xs, ys); q=0.01)
Makie.band(tuple.(xs, ys); nσ=2)
Makie.rangebars(tuple.(xs, ys); q=0.16)
Makie.rangebars(tuple.(xs, ys); q=0.16, nσ=2)
Makie.series(xs, ys)
Makie.series(tuple.(xs, ys); N=5)
end
Expand Down

0 comments on commit 0e29d67

Please sign in to comment.