From c8e6b967e523e2ce7e36e89bd6147dd66b623e79 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Tue, 7 Apr 2020 16:27:02 +0200 Subject: [PATCH] add errorbar test example --- src/examples.jl | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/examples.jl b/src/examples.jl index 37c9e19b..8f4aa316 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -946,6 +946,43 @@ const _examples = PlotExample[ end, ], ), + PlotExample( + "Error bars and array type recipes", + "", + [ + quote + begin + struct Measurement <: Number + val::Float64 + err::Float64 + end + value(m::Measurement) = m.val + uncertainty(m::Measurement) = m.err + + @recipe function f(::Type{T}, m::T) where T <: AbstractArray{<:Measurement} + if !(get(plotattributes, :seriestype, :path) in [:contour, :contourf, :contour3d, :heatmap, :surface, :wireframe, :image]) + error_sym = Symbol(plotattributes[:letter], :error) + plotattributes[error_sym] = uncertainty.(m) + end + value.(m) + end + + x = Measurement.(10sort(rand(10)), rand(10)) + y = Measurement.(10sort(rand(10)), rand(10)) + z = Measurement.(10sort(rand(10)), rand(10)) + surf = Measurement.((1:10) .* (1:10)', rand(10,10)) + + plot( + scatter(x, [x y], msw = 0), + scatter(x, y, z, msw = 0), + heatmap(x, y, surf), + wireframe(x, y, surf), + legend = :topleft + ) + end + end, + ], + ), ] # Some constants for PlotDocs and PlotReferenceImages