MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.37k stars 302 forks source link

plotting missing data after non-missing data leads to an error #3931

Open jonathanlilly opened 3 months ago

jonathanlilly commented 3 months ago

Plotting an array containing missing data after first plotting an array containing no missing data leads to an error:

using CairoMakie f = Figure() ax = Axis(f[1,1]) scatter!((1:4), [3,1,2,3]) scatter!((1:4), [1,missing,missing,2]) f

If alternatively we (i) switch the order or (ii) do not plot the non-missing version, then there is no error.

I doubt this is this desired behavior, but I could be wrong. Any ideas for a workaround?

Thanks!

Error message is as follows:

MethodError: no method matching create_dim_conversion(::Type{Union{Missing, Int64}})

Closest candidates are: create_dim_conversion(!Matched::Type{Categorical}) @ Makie ~/.julia/packages/Makie/We6MY/src/dim-converts/categorical-integration.jl:48 create_dim_conversion(!Matched::Type{<:Union{Period, Quantity, Unitful.Units}}) @ Makie ~/.julia/packages/Makie/We6MY/src/dim-converts/unitful-integration.jl:8 create_dim_conversion(!Matched::Type{<:Dates.AbstractTime}) @ Makie ~/.julia/packages/Makie/We6MY/src/dim-converts/dates-integration.jl:59 ...

jonathanlilly commented 3 months ago

Update: A workaround is to swap the missings for NaNs. This works fine:

using CairoMakie

f = Figure() ax = Axis(f[1,1]) scatter!((1:4), [3,1,2,3]) scatter!((1:4), [1,NaN,NaN,2]) f

Still if anyone can explain to me the cause of the original error I would be glad to know it.

jonathanlilly commented 3 months ago

On a related note, plotting an array of all missings generates an error, but plotting an array of all NaNs does not. Wouldn't the desired behavior for plotting missing data be just to plot nothing without an error?

f = Figure() ax = Axis(f[1,1]) lines!((1:4), [missing,missing,missing,missing]) f

f = Figure() ax = Axis(f[1,1]) lines!((1:4), [NaN,NaN,NaN,NaN]) f

jkrumbiegel commented 3 months ago

Probably something in the new pipeline steps has the ability to type-constrain itself to the first input argument, hence including Missing the next time errors. Should be possible to relax that behavior.

The difference between [missing,missing,missing,missing] and [NaN,NaN,NaN,NaN] is that we don't know what datatype is missing in the first one, as missing is a generic placeholder in Julia, not just for numbers. NaNs on the other hand are floats. Union{Missing,Float64}[missing, missing, missing, missing] would also work.