Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Makie.jl recipes #123

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ version = "2.7.2"
[deps]
Calculus = "49dc2e85-a5d0-5ad3-a950-438e2897f1b9"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ easy-to-use calculator.
measurements with their physical units, perform numerical integration
with [`QuadGK.jl`](https://github.com/JuliaMath/QuadGK.jl), numerical and
automatic differentiation, and much more.
* Integration with [`Plots.jl`](https://github.com/JuliaPlots/Plots.jl).
* Integration with [`Plots.jl`](https://github.com/JuliaPlots/Plots.jl) and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[`Makie.jl`](https://github.com/JuliaPlots/Makie.jl).

The method used to handle functional correlation is described in this paper:

Expand Down
37 changes: 32 additions & 5 deletions src/plot-recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,58 @@
### Code:

using RecipesBase
using Makie
leonvonrabenmond marked this conversation as resolved.
Show resolved Hide resolved

@recipe function f(y::AbstractArray{<:Measurement})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this file changed at all?

### Plots.jl

RecipesBase.@recipe function f(y::AbstractArray{<:Measurement})
yerror := uncertainty.(y)
value.(y)
end

@recipe function f(func::Function, x::AbstractArray{<:Measurement})
RecipesBase.@recipe function f(func::Function, x::AbstractArray{<:Measurement})
y = func.(x)
xerror := uncertainty.(x)
yerror := uncertainty.(y)
value.(x), value.(y)
end

@recipe function f(x::AbstractArray{<:Measurement}, y::AbstractArray{<:Measurement})
RecipesBase.@recipe function f(x::AbstractArray{<:Measurement}, y::AbstractArray{<:Measurement})
xerror := uncertainty.(x)
yerror := uncertainty.(y)
value.(x), value.(y)
end

@recipe function f(x::AbstractArray{<:Measurement}, y::AbstractArray)
RecipesBase.@recipe function f(x::AbstractArray{<:Measurement}, y::AbstractArray)
xerror := uncertainty.(x)
value.(x), y
end

@recipe function f(x::AbstractArray, y::AbstractArray{<:Measurement})
RecipesBase.@recipe function f(x::AbstractArray, y::AbstractArray{<:Measurement})
yerror := uncertainty.(y)
x, value.(y)
end

### Makie.jl

# PointBased plots
Makie.convert_arguments(P::Makie.PointBased, x::AbstractVector{<:Measurement}, y::AbstractVector{<:Measurement}) =
Makie.convert_arguments(P, value.(x), value.(y))
Makie.convert_arguments(P::Makie.PointBased, x::AbstractVector{<:Real}, y::AbstractVector{<:Measurement}) =
Makie.convert_arguments(P, x, value.(y))
Makie.convert_arguments(P::Makie.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))