Skip to content

Commit

Permalink
Added ribbon option to plot recipes (JuliaPhysics#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
kapple19 committed Jan 27, 2024
1 parent b23a969 commit fc888a4
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions ext/MeasurementsRecipesBaseExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,21 @@ else
using ..RecipesBase
end

@recipe function f(y::AbstractArray{<:Measurement})
yerror := uncertainty.(y)
unrecognised_uncertainty_plot_message = """
Unrecognized value for `uncertainty_plot` keyword.
Expecting either of `:bar` (default), `:ribbon`, or `:none`.
"""

@recipe function f(y::AbstractArray{<:Measurement}; uncertainty_plot = :bar)
if uncertainty_plot == :ribbon
ribbon := uncertainty.(y)
elseif uncertainty_plot == :bar
yerror := uncertainty.(y)
elseif uncertainty_plot == :none

else
error(unrecognised_uncertainty_plot_message)
end
value.(y)
end

Expand All @@ -47,9 +60,17 @@ end
value.(x), y
end

@recipe function f(x::AbstractArray, y::AbstractArray{<:Measurement})
yerror := uncertainty.(y)
x, value.(y)
@recipe function f(x::AbstractArray, y::AbstractArray{<:Measurement}; uncertainty_plot = :bar)
if uncertainty_plot == :ribbon
ribbon := uncertainty.(y)
elseif uncertainty_plot == :bar
yerror := uncertainty.(y)
elseif uncertainty_plot == :none

else
error(unrecognised_uncertainty_plot_message)
end
x, value.(y)
end

end

0 comments on commit fc888a4

Please sign in to comment.