JuliaPhysics / Measurements.jl

Error propagation calculator and library for physical measurements. It supports real and complex numbers with uncertainty, arbitrary precision calculations, operations with arrays, and numerical integration.
https://juliaphysics.github.io/Measurements.jl/stable/
MIT License
487 stars 37 forks source link

Plotting mixture of measurements and missing data #149

Open chriswaudby opened 1 year ago

chriswaudby commented 1 year ago

Hi,

I've got some results that are a mixture of measurements and missing data (type Vector{Union{Missing, Measurement{Float64}}}). However, I get a MethodError if I try to plot these:

plot([1±.1, 2±.3, missing, 4±.05])
MethodError: no method matching Float64(::Measurements.Measurement{Float64})
Closest candidates are:
(::Type{T})(::Real, !Matched::RoundingMode) where T<:AbstractFloat
@ Base rounding.jl:207
(::Type{T})(::T) where T<:Number
@ Core boot.jl:792
(::Type{T})(!Matched::AbstractChar) where T<:Union{AbstractChar, Number}
@ Base char.jl:50
...
convert(::Type{Float64}, ::Measurements.Measurement{Float64})@number.jl:7
setproperty!(::Plots.Extrema, ::Symbol, ::Measurements.Measurement{Float64})@Base.jl:38
expand_extrema!@axes.jl:425[inlined]
#113@axes.jl:444[inlined]
foreach(::Plots.var"#113#114"{Plots.Extrema}, ::Vector{Measurements.Measurement{Float64}})@abstractarray.jl:3073
expand_extrema!(::Plots.Axis, ::Vector{Measurements.Measurement{Float64}})@axes.jl:444
expand_extrema!(::Plots.Subplot{Plots.GRBackend}, ::RecipesPipeline.DefaultsDict)@axes.jl:479
_expand_subplot_extrema(::Plots.Subplot{Plots.GRBackend}, ::RecipesPipeline.DefaultsDict, ::Symbol)@pipeline.jl:433
add_series!(::Plots.Plot{Plots.GRBackend}, ::RecipesPipeline.DefaultsDict)@pipeline.jl:376
_process_seriesrecipe(::Any, ::Any)@series_recipe.jl:46
_process_seriesrecipes!(::Any, ::Any)@series_recipe.jl:27
recipe_pipeline!(::Any, ::Any, ::Any)@RecipesPipeline.jl:99
_plot!(::Plots.Plot, ::Any, ::Any)@plot.jl:223
#plot#188@plot.jl:102[inlined]
plot@plot.jl:93[inlined]

Not sure if this is best raised here or with Plots!

Best,

Chris

giordano commented 1 year ago

I presume the fix should be done here because the recipes live in this repository, but I'm not sure what the solution should be, I'm not familiar with how Plots deal with missing data. Is it only a matter of adding methods for Vector{Union{Missing, Measurement}} and sprinkle skipmissing around?