diff --git a/Project.toml b/Project.toml index ab1a313b..9181711b 100644 --- a/Project.toml +++ b/Project.toml @@ -13,12 +13,14 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" [weakdeps] Juno = "e5e0dc1b-0480-54bc-9374-aad01c23163d" +Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [extensions] MeasurementsJunoExt = "Juno" +MeasurementsMakieExt = "Makie" MeasurementsRecipesBaseExt = "RecipesBase" MeasurementsSpecialFunctionsExt = "SpecialFunctions" MeasurementsUnitfulExt = "Unitful" @@ -32,6 +34,7 @@ julia = "1" [extras] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" Juno = "e5e0dc1b-0480-54bc-9374-aad01c23163d" +Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01" SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" diff --git a/ext/MeasurementsMakieExt.jl b/ext/MeasurementsMakieExt.jl new file mode 100644 index 00000000..09bc94ef --- /dev/null +++ b/ext/MeasurementsMakieExt.jl @@ -0,0 +1,46 @@ +### plot-recipes.jl +# +# Maintainer: Mosè Giordano +# Keywords: uncertainty, error propagation, physics, plots +# +# This file is a part of Measurements.jl. +# +# License is MIT "Expat". +# +### Commentary: +# +# This file defines the recipes to plot Measurements vectors with Makie.jl package in 2D. +# +### Code: +module MeasurementsMakieExt + +if isdefined(Base, :get_extension) + using Measurements: Measurement, value, uncertainty + using Makie: Makie, PointBased, Errorbars, Band +else + using ..Measurements: Measurement, value, uncertainty + using ..Makie: Makie, PointBased, Errorbars, Band +end +# PointBased plots +Makie.convert_arguments(P::PointBased, x::AbstractVector{<:Measurement}, y::AbstractVector{<:Measurement}) = + convert_arguments(P, value.(x), value.(y)) +Makie.convert_arguments(P::PointBased, x::AbstractVector{<:Real}, y::AbstractVector{<:Measurement}) = + convert_arguments(P, x, value.(y)) +Makie.convert_arguments(P::PointBased, x::AbstractVector{<:Measurement}, y::AbstractVector{<:Real}) = + convert_arguments(P, value.(x), y) + +# errorbars +Makie.convert_arguments(P::Type{<:Errorbars}, x::AbstractVector{<:Measurement}, y::AbstractVector{<:Measurement}, e::AbstractVector{<:Measurement}) = + convert_arguments(P, value.(x), value.(y), uncertainty.(e)) +Makie.convert_arguments(P::Type{<:Errorbars}, x::AbstractVector{<:Measurement}, y::AbstractVector{<:Real}) = + convert_arguments(P, value.(x), y, uncertainty.(x)) +Makie.convert_arguments(P::Type{<:Errorbars}, x::AbstractVector{<:Real}, y::AbstractVector{<:Measurement}) = + convert_arguments(P, x, value.(y), uncertainty.(y)) + +# band +Makie.convert_arguments(P::Type{<:Band}, x::AbstractVector{<:Measurement}, y::AbstractVector{<:Measurement}) = + convert_arguments(P, value.(x), value.(y) - uncertainty.(y), value.(y) + uncertainty.(y)) +Makie.convert_arguments(P::Type{<:Band}, x::AbstractVector{<:Real}, y::AbstractVector{<:Measurement}) = + convert_arguments(P, x, value.(y) - uncertainty.(y), value.(y) + uncertainty.(y)) + +end #module