-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* makie extension * style typo * resolve some comments * add version bound for Makie * make sure convert arguments works * add test * fixup! add test * fixup! add test * fixup! add test * finish tests * drop support for pre 1.10 * allow Makie 0.22 * Apply suggestions from code review --------- Co-authored-by: longemen3000 <[email protected]> Co-authored-by: Mosè Giordano <[email protected]>
- Loading branch information
1 parent
0063930
commit ac5f583
Showing
5 changed files
with
82 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
julia-version: | ||
- "1.0" | ||
- "1" | ||
- "nightly" | ||
os: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
### plot-recipes.jl | ||
# | ||
# Maintainer: Mosè Giordano <mose AT gnu DOT org> | ||
# 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}) = | ||
Makie.convert_arguments(P, value.(x), value.(y)) | ||
Makie.convert_arguments(P::PointBased, x::AbstractVector{<:Real}, y::AbstractVector{<:Measurement}) = | ||
Makie.convert_arguments(P, x, value.(y)) | ||
Makie.convert_arguments(P::PointBased, x::AbstractVector{<:Measurement}, y::AbstractVector{<:Real}) = | ||
Makie.convert_arguments(P, value.(x), y) | ||
|
||
# errorbars | ||
Makie.convert_arguments(P::Type{<:Errorbars}, x::AbstractVector{<:Measurement}, y::AbstractVector{<:Measurement}, e::AbstractVector{<:Measurement}) = | ||
Makie.convert_arguments(P, value.(x), value.(y), uncertainty.(e)) | ||
Makie.convert_arguments(P::Type{<:Errorbars}, x::AbstractVector{<:Measurement}, y::AbstractVector{<:Real}) = | ||
Makie.convert_arguments(P, value.(x), y, uncertainty.(x)) | ||
Makie.convert_arguments(P::Type{<:Errorbars}, x::AbstractVector{<:Real}, y::AbstractVector{<:Measurement}) = | ||
Makie.convert_arguments(P, x, value.(y), uncertainty.(y)) | ||
|
||
# band | ||
Makie.convert_arguments(P::Type{<:Band}, x::AbstractVector{<:Measurement}, y::AbstractVector{<:Measurement}) = | ||
Makie.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}) = | ||
Makie.convert_arguments(P, x, value.(y) - uncertainty.(y), value.(y) + uncertainty.(y)) | ||
|
||
end #module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Makie: convert_arguments, Point, PointBased, Errorbars, Band, Vec | ||
|
||
@testset "PointBased" begin | ||
@test convert_arguments(PointBased(), [1, 2], [Measurements.measurement(1.0, 0.5), Measurements.measurement(2.0, 0.1)]) == (Point{2,Float64}[[1.0, 1.0], [2.0, 2.0]],) | ||
@test convert_arguments(PointBased(), [Measurements.measurement(1.0, 0.5), Measurements.measurement(2.0, 0.1)], [1, 2]) == (Point{2,Float64}[[1.0, 1.0], [2.0, 2.0]],) | ||
@test convert_arguments(PointBased(), [Measurements.measurement(1.0, 0.5), Measurements.measurement(2.0, 0.1)], | ||
[Measurements.measurement(1.0, 0.5), Measurements.measurement(2.0, 0.1)]) == (Point{2,Float64}[[1.0, 1.0], [2.0, 2.0]],) | ||
end | ||
|
||
@testset "Errorbars" begin | ||
@test convert_arguments(Errorbars, [1, 2], [Measurements.measurement(1.0, 0.5), Measurements.measurement(2.0, 0.1)]) == (Vec{4, Float64}[[1.0, 1.0, 0.5, 0.5], [2.0, 2.0, 0.1, 0.1]],) | ||
@test convert_arguments(Errorbars, [Measurements.measurement(1.0, 0.5), Measurements.measurement(2.0, 0.1)], [1, 2]) == (Vec{4, Float64}[[1.0, 1.0, 0.5, 0.5], [2.0, 2.0, 0.1, 0.1]],) | ||
# TODO: Currently intentionally ambigious. | ||
# @test convert_arguments(Errorbars, [Measurements.measurement(1.0, 0.5), Measurements.measurement(2.0, 0.1)], | ||
# [Measurements.measurement(1.0, 0.5), Measurements.measurement(2.0, 0.1)]) == (Vec{4, Float64}[[1.0, 1.0, 0.5, 0.5], [2.0, 2.0, 0.1, 0.1]],) | ||
@test convert_arguments(Errorbars, [Measurements.measurement(1.0, 0.5), Measurements.measurement(2.0, 0.1)], | ||
[Measurements.measurement(1.0, 0.5), Measurements.measurement(2.0, 0.1)], | ||
[Measurements.measurement(1.0, 0.5), Measurements.measurement(2.0, 0.1)]) == (Vec{4, Float64}[[1.0, 1.0, 0.5, 0.5], [2.0, 2.0, 0.1, 0.1]],) | ||
end | ||
|
||
@testset "Band" begin | ||
@test convert_arguments(Band, [1, 2], [Measurements.measurement(1.0, 0.5), Measurements.measurement(2.0, 0.1)]) == (Point{2, Float64}[[1.0, 0.5], [2.0, 1.9]], Point{2, Float64}[[1.0, 1.5], [2.0, 2.1]]) | ||
@test convert_arguments(Band, [Measurements.measurement(1.0, 0.5), Measurements.measurement(2.0, 0.1)], | ||
[Measurements.measurement(1.0, 0.5), Measurements.measurement(2.0, 0.1)]) == (Point{2, Float64}[[1.0, 0.5], [2.0, 1.9]], Point{2, Float64}[[1.0, 1.5], [2.0, 2.1]]) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters