Skip to content

Conversation

@daschw
Copy link
Member

@daschw daschw commented Apr 7, 2020

using Plots

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
)

cc: @briochemc

@daschw daschw added the backport label Apr 7, 2020
@daschw daschw merged commit 67ba06c into JuliaPlots:master Apr 7, 2020
@daschw daschw deleted the surface branch June 30, 2020 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant